Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

buffered-reader

Gagle2771.0.1

Binary and event-based data buffered readers.

buffer, reader, line, read line, file, read file, read text file, read binary file, binary

readme

THIS MODULE IS DEPRECATED, NO MORE FIXES, NO MORE ADDITIONS

binary-reader is the next binary reader module

Node BufferedReader

Node.js project

Binary and event-based data buffered readers

Show me! | Availability | Compatibility | 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...).

Show me!

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:

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.

Availability

Via npm:

npm install buffered-reader

Compatibility

✔ Node *


Documentation

Reference
Examples
Change Log
MIT License

changelog

v1.0.0 (04 Oct 2012) Complete code refactor for better maintenance. New classes "DataReader" and "BinaryReader". The "BufferedReader" class has been deprecated. Added new functions to "BinaryReader": "getOffset()" and "isOffsetOutOfWindow()". The "skip" function can move the offset backwards; a negative number of bytes can be skipped. Added constants to move the offset to the start and end of window: "BinaryReader.START_OF_WINDOW", "BinaryReader.END_OF_WINDOW". Added new setting to the "BinaryReader" constructor: "fromEnd". Some bug fixes.

v0.2.7 (17 Aug 2012) Updated errno-codes module.

v0.2.6 (05 Aug 2012) Better error management.

v0.2.5 (25 Jul 2012) The buffered reader is closed automatically on error. There's no need to close it again from outside.

v0.2.4 (25 Jul 2012) Fixed the byte offset in the "buffer" event when only a "buffer" event was set. Fixed the last byte offset of any data event. Now the last byte offset is -1. Added "pause()" and "resume()".

v0.2.3 (16 May 2012) Improved "read()" performance when the line event is not configured.

v0.2.2 (13 May 2012) Added a "byteOffset" parameter to the callback of emitted "byte", "character", "line" and "buffer" events.

v0.2.1 (13 May 2012) Improved "read()" performance.

v0.2.0 (02 May 2012) Fixed some bugs when the buffer had the same or less size than the bytes to read. Now the constructor receives an object in literal notation for the settings. Added start and end offsets parameters for limitting the range of the read. Added a "seek()" function for moving the file cursor for the next reading operation. Improved "skip()" performance. Now it calls to "seek()" function with the appropriate offset instead of reading the content into the buffer trying to simulate a jump.

v0.1.2 (29 Apr 2012) Added "skip()" function to skip bytes.

v0.1.1 (25 Apr 2012) Added "interrupt()" function to stop the file reading started with "read()".

v0.1.0 (25 Apr 2012) New feature. Now it's possible to read a chunk of bytes using internal buffers.

v0.0.6 (21 Apr 2012) Changed the way the module is required. Now can be required using "var BufferedReader = require ("buffered-reader");"

v0.0.5 (16 Apr 2012) Removed "getFileName()" internal function.

v0.0.4 (12 Apr 2012) "read()" can be called multiple times with the same "BufferedReader" instance.

v0.0.3 (11 Apr 2012) Fixed bug with Windows end of lines.

v0.0.2 (11 Apr 2012) First commit.