Giter Club home page Giter Club logo

Comments (4)

wdavidw avatar wdavidw commented on May 22, 2024

Hi, not completly sure i understand your need but i've just commited a write (and end) function that might help you. With those method, you can manually inject new data (string, array and object) to be writen to the output stream. u can look at 'test/write.js' for exemples and let me know if that help.

from node-csv.

jonseymour avatar jonseymour commented on May 22, 2024

David,

Thanks for that. I can see how that would be useful for writing a new stream of records.

My requirement is to progressively inject additional records as the input stream is parsed. I think the neatest way to model it would be to add 'beforeData' and 'afterData' events that are passed a function that can be called to write one or more records, and perhaps a parameter that indicates the number of records written.

These events would be emitted before and after the data event is emitted so that the additional records could be injected into the output stream before and after records read from the input stream.

The idea is to allow additional progressive summary or analysis records to be written into the output stream as the input stream is processed. So, for example, every 10 records in the input stream might be summarised by an 11th record in the output stream.

from node-csv.

wdavidw avatar wdavidw commented on May 22, 2024

you should be able to achieve this inside the transform method. if i remember well, this method has an interesting property which is to bypass a line if it return null while at the same time you could call the new write method, for exemple:

var test = csv()
.transform(function(data, index){
test.write([ index, data[0]--, 'and '+data[1] ]);
test.write([ index, data[0]++, 'or '+data[1] ]);
})

Would that work?

from node-csv.

jonseymour avatar jonseymour commented on May 22, 2024

Yes, I think that works for my purposes.

I have added an example which shows how to use this technique to duplicate the header line before each output line.

from node-csv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.