8000 GitHub - protobufjs/bytebuffer.js at 3.0.0
[go: up one dir, main page]

Skip to content

protobufjs/bytebuffer.js

Repository files navigation

ByteBuffer.js - The swiss army knife for binary data in JavaScript.

A fast and complete ByteBuffer implementation using either ArrayBuffers in the browser or node Buffers under node.js, generated from a single source tree through MetaScript.

If you are looking for ByteBuffer.js 2 (ArrayBuffers only), that's the branch.

What can it do?

  • 8, 16, 32 and 64 bit signed and unsigned integers
  • 32 and 64 bit floats
  • Big and little endianness
  • Varints as used in protobuf (32 and 64 bit, zig-zag)
  • Base64, binary, debug, hex and utf8 encodings
  • Handy string and debugging utilities
  • Relative and absolute zero-copy operations wherever possible
  • Transparent resizing when using unknown-length data
  • Chaining of all operations that do not return a specific value
  • Slicing, appending, prepending, reversing, flip, mark, reset, etc.

More

  • CommonJS, AMD and shim compatible
  • Also available via npm
  • Compiled through Closure Compiler using ADVANCED_OPTIMIZATIONS (fully annotated, includes externs and source map)
  • Fully documented using jsdoc3
  • Well tested through test.js
  • Zero production dependencies (Long.js is optional)

Usage

Node.js

  • Install: npm install bytebuffer
var ByteBuffer = require("bytebuffer");
var bb = new ByteBuffer();
bb.writeIString("Hello world!").flip();
console.log(bb.readIString()+" from ByteBuffer.js");

Browser

Optionally depends on Long.js for long (int64) support. If you do not require long support, you can skip the Long.js include.

<script src="Long.min.js"></script>
<script src="ByteBufferAB.min.js"></script>
var ByteBuffer = dcodeIO.ByteBuffer;
var bb = new ByteBuffer();
bb.writeIString("Hello world!").flip();
alert(bb.readIString()+" from ByteBuffer.js");

AMD

Optionally depends on Long.js for long (int64) support. If you do not require long support, you can skip the Long.js config. Require.js example:

require.config({
    "paths": {
        "Long": "/path/to/Long.js"
        "ByteBuffer": "/path/to/ByteBufferAB.js"
    }
});
require(["ByteBuffer"], function(ByteBuffer) {
    var bb = new ByteBuffer();
    bb.writeIString("Hello world!").flip();
    alert(bb.readIString()+" from ByteBuffer.js");
});

Downloads

Documentation

Tests (& Examples) Build Status

Support for IE<10, FF<15, Chrome<9 etc.

  • Requires working ArrayBuffer & DataView implementations (i.e. use a polyfill)

Contributors

Dretch (IE8 compatibility)

License

Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html

About

A fast and complete ByteBuffer implementation using either ArrayBuffers in the browser or Buffers under node.js.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 10

0