Comments (5)
Hi,
I was trying to parse the csv file which is quite big file and i wanted to parse the file upto paritcular point where i get the data i wanted and wanted the parsing to stop after that but there is no option of stopping the parsing and if there is option to stop parsing how to do that .
actually there was one logic i developed to stop the parsing to assume the content after the data wanted to take as comment but i was not able to use that option.
from fast-csv.
http://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options
fs.createReadStream('sample.csv', {start: 0, end: 1000}) //read the first 1000 bytes
.pipe( csv({headers: true}) )
.on('data', function(row){
console.log('Got row', row);
})
If you want to read exactly half of a file, you can use fs.stat to get the size, then divide it by two.
Note that you may get an invalid row at the end if a row gets cut off in the middle.
from fast-csv.
Thanks for the reply ,
but i wanted to parse like first 20 or may be first 30 rows from csv file .so, how i can get the byte size for these 20 or 30 rows of file.
from fast-csv.
You can't get the byte size for a certain number of rows unless you already know what's in the file, and in order to do that you (usually) have to read the file.
Here's an example which will read 20 rows and then stop.
var fs = require('fs');
var csv = require('fast-csv');
var fileStream = fs.createReadStream('sample.csv', 'utf8');
var csvStream = csv({headers: true});
fileStream.pipe(csvStream);
var rows = [];
var onData = function(row){
rows.push(row);
if (rows.length == 20) {
csvStream.emit('donereading'); //custom event for convenience
}
};
csvStream.on('data', onData);
csvStream.on('donereading', function(){
fileStream.close();
csvStream.removeListener('data', onData);
console.log('got 20 rows', rows);
});
from fast-csv.
Thanks for Reply.
Problem is solved.
from fast-csv.
Related Issues (20)
- [BUG] `comment` doesn't work when first field in line is escaped
- [BUG]parse csv file when row has datetime data,return data miss second HOT 1
- convert JSON object to CSV string
- [FEATURE] Support transform FormatterOptionsArgs of type 'A -> A | B -> B'
- Documentation for other methods? HOT 1
- Trailing comma behaviour has changed between 4.3.1 and latest
- How to parse a csv file from S3 and upload to S3 without keeping in a memory HOT 4
- [BUG] CSV Streams severely limited in capacity HOT 2
- [FEATURE]sfdx version --verbose --json
- Homepage link on npm 404s HOT 1
- [BUG] The `|` character causes unnecessary quotation of the value HOT 1
- [FEATURE] Is this project dead? HOT 6
- [BUG] : Streaming gets stopped and goes to "end" event if row encounters "numerics at the end of the string" like "something_10". HOT 1
- Can not open the site of docs HOT 1
- [BUG] Getting started doc link is broken HOT 4
- [FEATURE] Parsing row issue HOT 1
- [FEATURE] Move to Coveralls GitHub Action
- [FEATURE] Documentation request: example of exception in on('headers') handler
- [BUG] Breaking changes in the new version 5? HOT 2
- [BUG] Format concats lines when reading from multiple streams to one file
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 fast-csv.