Comments (4)
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.
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.
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.
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)
- YYYY-01-01 getting parsed as the previous year HOT 1
- a solution to repair rows when using columns HOT 1
- Link to Pipe recipe in docs is broken. HOT 2
- CSV Parsing fail when extra cell with no column HOT 1
- Function parse returns "any" - Could it be made generic? HOT 4
- csv-parse stream will process the whole buffer even with back pressure. HOT 6
- Error message when using vite
- Option `to` and `to_line` results in `ERR_STREAM_PREMATURE_CLOSE` HOT 4
- When `bom` and `skipRecordsWithError` skip event is not raised for skipped records HOT 7
- How can I convert json object with array to csv? HOT 1
- Date parse bug HOT 2
- Parse dot notation columns into nested objects HOT 4
- CSV Parse breaks on comment characters that are also in rows HOT 4
- csv-parse fails to parse very large CSV files
- User-defined value generation HOT 5
- support headers as comment HOT 3
- Support parsing of quote characters within quotes HOT 2
- Ignore comment lines for the from_line value
- bug: Fatal JavaScript invalid size error HOT 1
- Error Lines Property Should Return All Lines of error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-csv.