Giter VIP home page Giter VIP logo

node-bufferlist's Introduction

BufferList

BufferList provides an interface to treat a linked list of buffers as a single stream. This is useful for events that produce a many small Buffers, such as network streams.

Installation

Install using npm: npm install bufferlist

Or, check out the repository and have npm link to your development copy. This is useful for developing the library, and is necessary when running the tests, since they refer to the installed names of the library files. git clone http://github.com/substack/node-bufferlist.git cd node-bufferlist npm link .

Simple Bufferlist Example

#!/usr/bin/env node
var sys = require('sys');
var Buffer = require('buffer').Buffer;
var BufferList = require('bufferlist').BufferList;

var b = new BufferList;
['abcde','xyz','11358'].forEach(function (s) {
    var buf = new Buffer(s.length);
    buf.write(s);
    b.push(buf);
});

sys.puts(b.take(10)); // abcdexyz11

Binary

This distribution also contains a Binary module for parsing these bufferlists.

Simple Binary Example

#!/usr/bin/env node

var sys = require('sys');
var Buffer = require('buffer').Buffer;
var BufferList = require('bufferlist').BufferList;
var Binary = require('bufferlist/binary').Binary;

var bufferList = new BufferList;
var binary = Binary(bufferList)
    .getWord16be('xLen')
    .getBuffer('xs', 'xLen')
    .tap(function (vars) {
        vars.moo = 'xs:' + vars.xLen + ':' + vars.xs;
    })
    .end()
;

var buf = new Buffer(6);
buf.write('\x00\x04meow', 'binary');
bufferList.push(buf);

sys.puts(binary.vars.moo); // xs:4:meow

See Also

See the examples/ directory for more involved examples.

See http://github.com/substack/node-rfb for a practical application of this distribution.

node-bufferlist's People

Contributors

pkrumins avatar

Stargazers

Jeremy Johnstone avatar

Watchers

Jeremy Johnstone avatar James Cloos avatar  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.