Giter Site home page Giter Site logo

node-buffer-writer's Introduction

buffer-writer

Build Status

Fast & efficient buffer writer used to keep memory usage low by internally recycling a single large buffer.

Used as the binary protocol writer in node-postgres

Since postgres requires big endian encoding, this only writes big endian numbers for now, but can & probably will easily be extended to write little endian as well.

I'll admit this has a few postgres specific things I might need to take out in the future, such as addHeader

api

var writer = new (require('buffer-writer')());

writer.addInt32(num)

Writes a 4-byte big endian binary encoded number to the end of the buffer.

writer.addInt16(num)

Writes a 2-byte big endian binary encoded number to the end of the buffer.

writer.addCString(string)

Writes a string to the buffer utf8 encoded and adds a null character (\0) at the end.

var buffer = writer.addHeader(char)

Writes the 5 byte PostgreSQL required header to the beginning of the buffer. (1 byte for character, 1 BE Int32 for length of the buffer)

var buffer = writer.join()

Collects all data in the writer and joins it into a single, new buffer.

var buffer = writer.flush(char)

Writes the 5 byte postgres required message header, collects all data in the writer and joins it into a single, new buffer, and then resets the writer.

thoughts

This is kind of node-postgres specific. If you're interested in using this for a more general purpose thing, lemme know. I would love to work with you on getting this more reusable for your needs.

license

MIT

node-buffer-writer's People

Contributors

brianc avatar tomhughes avatar

Watchers

 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.