Skip to content

Commit f7fda5a

Browse files
committed
README, cleanup
1 parent 53c5bb1 commit f7fda5a

File tree

8 files changed

+76
-60
lines changed

8 files changed

+76
-60
lines changed

dist/ByteBufferAB.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@
702702
if (!this.noAssert) {
703703
if (typeof value === 'number')
704704
value = Long.fromNumber(value);
705-
if (typeof value !== 'number' && !(value && value instanceof Long))
705+
else if (!(value && value instanceof Long))
706706
throw(new TypeError("Illegal value: "+value+" (not an integer or Long)"));
707707
if (typeof offset !== 'number' || offset % 1 !== 0)
708708
throw(new TypeError("Illegal offset: "+offset+" (not an integer)"));
@@ -781,7 +781,7 @@
781781
if (!this.noAssert) {
782782
if (typeof value === 'number')
783783
value = Long.fromNumber(value);
784-
if (typeof value !== 'number' && !(value && value instanceof Long))
784+
else if (!(value && value instanceof Long))
785785
throw(new TypeError("Illegal value: "+value+" (not an integer or Long)"));
786786
if (typeof offset !== 'number' || offset % 1 !== 0)
787787
throw(new TypeError("Illegal offset: "+offset+" (not an integer)"));
@@ -1241,7 +1241,7 @@
12411241
if (!this.noAssert) {
12421242
if (typeof value === 'number')
12431243
value = Long.fromNumber(value);
1244-
if (typeof value !== 'number' && !(value && value instanceof Long))
1244+
else if (!(value && value instanceof Long))
12451245
throw(new TypeError("Illegal value: "+value+" (not an integer or Long)"));
12461246
if (typeof offset !== 'number' || offset % 1 !== 0)
12471247
throw(new TypeError("Illegal offset: "+offset+" (not an integer)"));

dist/ByteBufferAB.min.js

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

dist/ByteBufferAB.min.js.gz

14 Bytes
Binary file not shown.

dist/ByteBufferAB.min.map

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/ByteBufferNB.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ module.exports = (function() {
776776
if (!this.noAssert) {
777777
if (typeof value === 'number')
778778
value = Long.fromNumber(value);
779-
if (typeof value !== 'number' && !(value && value instanceof Long))
779+
else if (!(value && value instanceof Long))
780780
throw(new TypeError("Illegal value: "+value+" (not an integer or Long)"));
781781
if (typeof offset !== 'number' || offset % 1 !== 0)
782782
throw(new TypeError("Illegal offset: "+offset+" (not an integer)"));
@@ -892,7 +892,7 @@ module.exports = (function() {
892892
if (!this.noAssert) {
893893
if (typeof value === 'number')
894894
value = Long.fromNumber(value);
895-
if (typeof value !== 'number' && !(value && value instanceof Long))
895+
else if (!(value && value instanceof Long))
896896
throw(new TypeError("Illegal value: "+value+" (not an integer or Long)"));
897897
if (typeof offset !== 'number' || offset % 1 !== 0)
898898
throw(new TypeError("Illegal offset: "+offset+" (not an integer)"));
@@ -1397,7 +1397,7 @@ module.exports = (function() {
13971397
if (!this.noAssert) {
13981398
if (typeof value === 'number')
13991399
value = Long.fromNumber(value);
1400-
if (typeof value !== 'number' && !(value && value instanceof Long))
1400+
else if (!(value && value instanceof Long))
14011401
throw(new TypeError("Illegal value: "+value+" (not an integer or Long)"));
14021402
if (typeof offset !== 'number' || offset % 1 !== 0)
14031403
throw(new TypeError("Illegal offset: "+offset+" (not an integer)"));

dist/README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
Distributions
22
=============
3-
* **ByteBufferAB** uses an ArrayBuffer as its backing buffer and is compatible with modern browsers.
4-
* **ByteBufferNB** uses a node Buffer as its backing buffer and is compatible with node.js only, where it performs a lot
5-
better than *ByteBufferAB*.
6-
7-
While both versions are fully API-compatible, some internals like what `ByteBuffer#buffer` references and how it is
8-
allocated differ. There is, however, no abstraction layer in between, as pretty much everything has been optimized to
9-
work with the exact API it is based upon, providing a developer with a reliable API to write efficient code only once
10-
targeting both node.js and the browser.
3+
4+
ByteBuffer uses either ArrayBuffers in the browser or Buffers under node.js.
5+
6+
### Browsers: ArrayBuffers
7+
8+
* **[ByteBufferAB.js](https://raw.githubusercontent.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferAB.js)**
9+
uses an ArrayBuffer as its backing buffer, accessed through a DataView.
10+
11+
* **[ByteBifferAB.min.js](https://raw.githubusercontent.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferAB.min.js)**
12+
has been compiled with Closure Compiler using `--compilation_level=ADVANCED_OPTIMIZATIONS`.
13+
14+
* **[ByteBufferAB.min.js.gz](https://raw.githubusercontent.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferAB.min.js.gz)**
15+
has also been gzipped using `-9`.
16+
17+
* **[ByteBufferAB.min.map](https://raw.githubusercontent.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferAB.min.map)**
18+
is the source map generated by Closure Compiler.
19+
20+
### node.js: Buffers
21+
22+
* **[ByteBufferNB.js](https://raw.githubusercontent.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferNB.js)**
23+
uses a node Buffer as its backing buffer.
24+
25+
When installed as an [npm package](https://www.npmjs.org/package/bytebuffer), both versions are available.
26+
`exports` and `exports.ByteBufferNB` point at ByteBufferNB, `exports.ByteBufferAB` points at ByteBufferAB.

src/helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ function assertInteger(value, unsigned) {
3939
* @inner
4040
*/
4141
function assertLong(value, unsigned) {
42-
if (typeof value === 'number' && value % 1 !== 0) {
43-
return unsigned ? value >>> 0 : value | 0;
42+
if (typeof value === 'number') {
43+
return Long.fromNumber(value);
4444
} else if (value && value instanceof Long) {
4545
if (typeof unsigned !== 'undefined') {
4646
if (unsigned && !value.unsigned) return value.toUnsigned();

src/macros.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ASSERT_LONG = function(varValue, unsigned) {
3333
}
3434
writeln(__+'else');
3535
} else {
36-
writeln(__+'if (typeof '+varValue+' !== \'number\' && !('+varValue+' && '+varValue+' instanceof Long))');
36+
writeln(__+'else if (!('+varValue+' && '+varValue+' instanceof Long))');
3737
}
3838
writeln(__+' throw(new TypeError("Illegal '+varValue+': "+'+varValue+'+" (not an integer or Long)"));');
3939
} else {

0 commit comments

Comments
 (0)