Skip to content

Commit 333a0d7

Browse files
committed
2.0.0-pre
1 parent fc5590f commit 333a0d7

File tree

13 files changed

+988
-885
lines changed

13 files changed

+988
-885
lines changed

ByteBuffer.js

Lines changed: 216 additions & 172 deletions
Large diffs are not rendered by default.

ByteBuffer.min.js

Lines changed: 50 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ByteBuffer.min.map

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

ByteBuffer.noexpose.js

Lines changed: 214 additions & 171 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 22 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,28 @@
11
![ByteBuffer.js - A Java-like ByteBuffer](https://raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.png)
22
======================================
3-
Provides a Java-like, Netty-inspired ByteBuffer implementation using typed arrays. It also tries to abstract a bit of
3+
Provides a full-features ByteBuffer implementation using typed arrays. It also tries to abstract a bit of
44
the complexity away by providing convenience methods for those who just want to write stuff without caring about signed,
5-
unsigned and the actual bit sizes. It's also one of the components driving [ProtoBuf.js](https://github.com/dcodeIO/ProtoBuf.js).
6-
7-
ByteBuffer
8-
----------
9-
* Mimics [Java ByteBuffers](http://docs.oracle.com/javase/1.5.0/docs/api/java/nio/ByteBuffer.html) as close as reasonable while using typed array terms
10-
* Full 64bit support via [Long.js](https://github.com/dcodeIO/Long.js) (optional)
11-
* Simple allocation (`new ByteBuffer(capacity[, littleEndian])` or `ByteBuffer.allocate(capacity[, littleEndian])`)
12-
* Wrapping of quite everything which is or includes an ArrayBuffer (`ByteBuffer.wrap(buffer[, littleEndian])`)
13-
* Cloning using the same (`ByteBuffer#clone()`) and copying using an independent backing buffer (`ByteBuffer#copy()`)
14-
* Slicing using the same (`ByteBuffer#slice(begin, end)`) and using an indepentent backing buffer (`ByteBuffer#sliceAndCompact(begin, end)`)
15-
* Manual offset (`ByteBuffer#offset` and `ByteBuffer#length`) and array manipulation (`ByteBuffer#array`)
16-
* Remaining readable bytes (`ByteBuffer#remaining()`) and backing buffer capacity getters (`ByteBuffer#capacity()`)
17-
* Explicit (`ByteBuffer#resize(capacity)`) and implicit resizing (`ByteBuffer#ensureCapacity(capacity)`)
18-
* Efficient implicit resizing by doubling the current capacity
19-
* Flipping (`ByteBuffer#flip()`), marking (`ByteBuffer#mark([offset])`) and resetting (`ByteBuffer#reset()`)
20-
* Compacting of the backing buffer (`ByteBuffer#compact()`)
21-
* Conversion to ArrayBuffer (`ByteBuffer#toArrayBuffer([forceCopy])`) (i.e. to send data over the wire, e.g. a WebSocket
22-
with `binaryType="arraybuffer"`)
23-
* Conversion to Buffer (`ByteBuffer#toBuffer()`) if running inside of node.js
24-
* Reversing (`ByteBuffer#reverse()`), appending (`ByteBuffer#append(src[, offset])`) and prepending
25-
(`ByteBuffer#prepend(src[, offset])`) of other ByteBuffers with implicit capacity management
26-
* Explicit destruction (`ByteBuffer#destroy()`)
27-
* `ByteBuffer#writeUint/Int8/16/32/64(value[, offset])` and `ByteBuffer#readUint/Int8/16/32/64([offset])`
28-
* `ByteBuffer#writeVarint32/64(value[, offset])` and `ByteBuffer#readVarint32/64([offset])` to write a base 128
29-
variable-length integer as used in [protobuf](https://developers.google.com/protocol-buffers/docs/encoding#varints)
30-
* `ByteBuffer#writeZigZagVarint32/64(value[, offset])` and `ByteBuffer#readZigZagVarint32/64([offset])` to write a
31-
zig-zag encoded base 128 variable-length integer as used in protobuf for efficient encoding of signed values
32-
* `ByteBuffer#writeFloat32/64(value[, offset])` and `ByteBuffer#readFloat32/64([offset])`
33-
* `ByteBuffer#write/readByte`, `ByteBuffer#write/readShort`, `ByteBuffer#write/readInt`, `ByteBuffer#write/readLong`
34-
(all signed), `ByteBuffer#write/readVarint` and `ByteBuffer#write/readZigZagVarint` (both 32bit signed),
35-
`ByteBuffer#write/readFloat`, `ByteBuffer#write/readDouble` aliases for the above for convenience
36-
* `ByteBuffer#writeUTF8String(str[, offset])`, `ByteBuffer#readUTF8String(chars[, offset])` and
37-
`ByteBuffer#readUTF8StringBytes(length[, offset])` using the included UTF8 en-/decoder (full 6 bytes,
38-
[ref](http://en.wikipedia.org/wiki/UTF-8#Description))
39-
* `ByteBuffer.encode64(bb)`, `ByteBuffer.decode64(str)` and `ByteBuffer#toBase64()` using the included Base64
40-
en/-decoder.
41-
* `ByteBuffer#writeLString(str[, offset]))` and `ByteBuffer#readLString([offset])` to write respectively read a
42-
length-prepended (number of characters as UTF8 char) string
43-
* `ByteBuffer#writeVString(str[, offset]))` and `ByteBuffer#readVString([offset])` to write respectively read a
44-
length-prepended (number of bytes as base 128 variable-length 32bit integer) string
45-
* `ByteBuffer#writeCString(str[, offset])` and `ByteBuffer#readCString([offset])` to write respectively read a
46-
NULL-terminated (Uint8 0x00) string
47-
* `ByteBuffer#writeJSON(data[, offset[, stringify]])` and `ByteBuffer#readJSON([offset[, parse]])` to write respectively
48-
read arbitraty object data. Allows overriding the default stringify (default: JSON.stringify) and parse (default:
49-
JSON.parse) implementations.
50-
* All with implicit offset advance if the offset parameter is omitted or without, if specified
51-
* Chaining of all operations that allow this (i.e. do not return some specific value like in read operations), e.g.
52-
53-
```javascript
54-
var bb = new ByteBuffer();
55-
...
56-
bb.reset().writeInt(1).writeLString("Hello world!").flip().compact()...
57-
```
58-
59-
* Switching between little endian and big endian byte order through `ByteBuffer#LE()` and `ByteBuffer#BE()`, e.g.
60-
61-
```javascript
62-
var bb = new ByteBuffer(8).LE().writeInt(1).BE().writeInt(2).flip(); // toHex: <01 00 00 00 00 00 00 02>
63-
```
64-
65-
* `ByteBuffer#toString([enc])`, `ByteBuffer#toHex([wrap])`, `ByteBuffer#toASCII([wrap])`, `ByteBuffer#toUTF8()`,
66-
`ByteBuffer#toBase64()` and `ByteBuffer#printDebug()` (emits hex + ASCII + offsets to console, looks like your
67-
favourite hex editor) for pain-free debugging
68-
5+
unsigned and the actual bit sizes. It's also one of the components driving [ProtoBuf.js](https://github.com/dcodeIO/ProtoBuf.js)
6+
and the [PSON](https://github.com/dcodeIO/PSON) reference implementation.
7+
8+
*Note:* The API behind toHex and toString has changed with ByteBuffer 2.0.0, which is a generally revised release, in
9+
favor of making this more intuitive.
10+
11+
What can it do?
12+
---------------
13+
* Mimics Java ByteBuffers as close as reasonable while using typed array terms
14+
* Signed and unsigned integers (8, 16, 32, 64 bit through [Long.js](https://github.com/dcodeIO/Long.js)) with endianness support
15+
* Varints as known from protobuf including zig-zag encoding
16+
* Includes an UTF8 and Base64 en-/decoder
17+
* C-strings, Varint-prefixed strings and UTF8 length-prefixed strings
18+
* Rich string toolset (to hex, base64, utf8, debug, columns)
19+
* Relative and absolute zero-copy operations
20+
* Automatic resizing (always doubles)
21+
* Chaining of all operations that do not return a specific value
22+
* Slicing, appending, prepending etc.
23+
24+
And much more... (see the API documentation)
25+
6926
Features
7027
--------
7128
* [CommonJS](http://www.commonjs.org/) compatible

bower.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "bytebuffer",
3-
"version": "1.4.0",
3+
"version": "2.0.0-pre",
44
"author": "Daniel Wirtz <[email protected]>",
5-
"description": "ByteBuffer.js: A Java-like, Netty-inspired ByteBuffer implementation using typed arrays.",
5+
"description": "A full-featured ByteBuffer implementation using typed arrays.",
66
"main": "ByteBuffer.js",
77
"keywords": ["net", "array", "buffer", "arraybuffer", "typed array", "bytebuffer", "json", "websocket", "webrtc"],
88
"dependencies": {
9-
"long": "latest"
9+
"long": "latest"
1010
},
1111
"license": "Apache-2.0"
12-
}
12+
}

build.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@
2121
*/
2222

2323
var Preprocessor = require("preprocessor"),
24-
fs = require("fs");
24+
fs = require("fs"),
25+
pkg = require(__dirname+"/package.json");
2526

2627
var pp = new Preprocessor(fs.readFileSync(__dirname+"/src/ByteBuffer.js"), __dirname+"/src");
27-
fs.writeFileSync(__dirname+"/ByteBuffer.js", pp.process());
28+
fs.writeFileSync(__dirname+"/ByteBuffer.js", pp.process({
29+
"VERSION": pkg.version
30+
}));
31+
32+
pp = new Preprocessor(fs.readFileSync(__dirname+"/src/bower.json"), __dirname+"/src");
33+
fs.writeFileSync(__dirname+"/bower.json", pp.process({
34+
"VERSION": pkg.version
35+
}));

0 commit comments

Comments
 (0)