joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.84k stars 784 forks source link

Ability to read text file line by line #495

Open omatrot opened 4 years ago

omatrot commented 4 years ago

This PR is about reading text files line by line with an event emitted at each line. The trick is to send -1 to bufferSize and 'utf8' to encoding in readStream.

Traviskn commented 4 years ago

Can you elaborate on the motivation for this feature? I'm curious what problem it will solve and how a developer would use it. Does it add new API to rn-fetch-blob? If it does add new API, can you update any relevant README/docs?

omatrot commented 4 years ago

The motivation for me was to be able to process a .csv file line by line. Without this modification, it would have been necessary to guess the line length to be sure to allocate a buffer that would hold at least one line.

Furthermore, the ability to pace the onData callback was very usefull in my use case where timing was very important.

This is not a new API, just some parameter tricks to switch to this particular mode.

I will update the Docs later this evening.

omatrot commented 4 years ago

I've modified the Wiki accordingly. Please let me know if you would like something else.