https://github.com/trustvox/buffered-text-reader
Extract text file's content in a buffered approach
https://github.com/trustvox/buffered-text-reader
Last synced: 6 months ago
JSON representation
Extract text file's content in a buffered approach
- Host: GitHub
- URL: https://github.com/trustvox/buffered-text-reader
- Owner: trustvox
- License: mit
- Created: 2019-10-30T19:49:29.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T23:52:36.000Z (over 2 years ago)
- Last Synced: 2024-04-25T17:43:33.643Z (about 1 year ago)
- Language: JavaScript
- Size: 304 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BufferedReader
A module to read text files in the browser without having to load the whole content into memory.
## API
### Constructor
Creates an instance of BufferedReader
```js
const bufferedReader = new BufferedReader(file);
```Where `file` is a [HTML5 File](https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications).
### ReadLine
Reads the next available line. This method can be called multiple times til `EOL` is reached.
```js
const line = await bufferedReader.readLine();
```To check if the `EOL` is reached, you can query it by using `isEOL()`.
```js
while (!bufferedReader.isEOL()) {
const line = await bufferedReader.readLine();
}
```You can, optionally, defines the chunk size to be used when trying to read a line. The default is set to 1024 bytes, but it can be overridden when calling `readLine`.
```js
const line = await bufferedReader.readLine(2048);
const line = await bufferedReader.readLine(16);
```