# buffered-reader

> Binary and event-based data buffered readers.

Latest version **1.0.1** (published 2012-10-12) · 0 weekly downloads

## Install

```sh
npm install buffered-reader
pnpm add buffered-reader
yarn add buffered-reader
bun add buffered-reader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2012-10-12 |
| First published | 2012-04-11 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gabriel Llamas |
| Maintainers | Gagle |
| Keywords | buffer, reader, line, read line, file, read file, read text file, read binary file, binary |

## Links

- npm: https://www.npmjs.com/package/buffered-reader
- Repository: https://github.com/Gagle/Node-BufferedReader
- npm.io page: https://npm.io/package/buffered-reader

## Dependencies (1)

- [errno-codes](https://npm.io/package/errno-codes.md) *

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2012-10-12
- 1.0.0 — 2012-10-05
- 0.2.7 — 2012-08-17
- 0.2.6 — 2012-08-05
- 0.2.5 — 2012-07-25
- 0.2.4 — 2012-07-25
- 0.2.3 — 2012-07-25
- 0.2.2 — 2012-05-13
- 0.2.1 — 2012-05-13
- 0.2.0 — 2012-05-02
- 0.1.2 — 2012-04-29
- 0.1.1 — 2012-04-25
- 0.1.0 — 2012-04-25
- 0.0.6 — 2012-04-21
- 0.0.5 — 2012-04-15
- … 3 more at https://npm.io/package/buffered-reader/versions

## README

<a name="start"></a>

Node BufferedReader
===================

_Node.js project_

#### Binary and event-based data buffered readers ####

[Show me!](#showme) | [Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)

Version: 1.0.1

When you need to read a file you typically read a chunk of bytes called "buffer" to avoid multiple calls to the underlying I/O layer, so instead of reading directly from the disk, you read from the previous filled buffer. Doing this you win performance.

This library allows you to read files without worry about the buffers. There are two ways to read the files. The first can only read binary data and has a pointer to move along the file (seek, skip, read). The second performs a read from the beginning to the end of the file and emits different events (byte, character, line, buffer...).

<a name="showme"></a>
#### Show me! [↑](#start) ####

```javascript
var reader = require ("buffered-reader");
var BinaryReader = reader.BinaryReader;
var DataReader = reader.DataReader;

var close = function (binaryReader, error){
	if (error) console.log (error);
	
	binaryReader.close (function (error){
		if (error) console.log (error);
	});
};

var file = "file";
var offset;

new DataReader (file, { encoding: "utf8" })
		.on ("error", function (error){
			console.log (error);
		})
		.on ("line", function (line, nextByteOffset){
			if (line === "Phasellus ultrices ligula sed odio ultricies egestas."){
				offset = nextByteOffset;
				this.interrupt ();
			}
		})
		.on ("end", function (){
			new BinaryReader (file)
					.seek (offset, function (error){
						if (error) return close (this, error);
						
						this.read (9, function (error, bytes, bytesRead){
							if (error) return close (this, error);
							
							console.log (bytes.toString ()); //Prints: Curabitur
							
							close (this);
						});
					});
		})
		.read ();
```

file:

```text
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Morbi convallis nibh massa, eu varius felis.

Phasellus ultrices ligula sed odio ultricies egestas.
Curabitur pretium magna in diam accumsan dignissim.
Phasellus et tortor eu orci suscipit vehicula.
Phasellus pulvinar mauris in purus consequat vel congue orci hendrerit.
Pellentesque eget arcu magna, suscipit imperdiet eros.
```

***

<a name="availability"></a>
#### Availability [↑](#start) ####

Via npm:

```
npm install buffered-reader
```

***

<a name="compatibility"></a>
#### Compatibility [↑](#start) ####

✔ Node *

***

<a name="documentation"></a>
#### Documentation [↑](#start) ####
 
[Reference](https://github.com/Gagle/Node-BufferedReader/wiki/Reference)  
[Examples](https://github.com/Gagle/Node-BufferedReader/tree/master/examples)  
[Change Log](https://github.com/Gagle/Node-BufferedReader/wiki/Change-Log)  
[MIT License](https://github.com/Gagle/Node-BufferedReader/blob/master/LICENSE)

---
_Source: https://npm.io/package/buffered-reader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
