Giter VIP home page Giter VIP logo

node-bufferedreader's Introduction

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

node-bufferedreader's People

Contributors

blakmatrix avatar

Watchers

Cesar Santana avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.