toots / buffer-browserify Goto Github PK
View Code? Open in Web Editor NEWnode's buffer module, but for the browser.
License: MIT License
node's buffer module, but for the browser.
License: MIT License
I am getting an empty assert object, and seems to be related to a circular dependency between buffer and assert. anybody else experiencing this problem?
I ran into this while writing a browser side Writable Stream.
The problem is basically that Buffer.isBuffer(buf)
returns false
although it is one. This is due to buf instanceof Buffer
returning false
-- I tried this in the browser console as well.
I commented on my workaround here.
You could use this project as a test bed, i.e.:
npm install d3-gauge-writable
npm explore d3-gauge-writable
npm start
You should then be able to debug into d3-gauge-writable
assuming you enabled source maps on your browser.
I tried to run this module with the Buffer tests from node
( https://github.com/joyent/node/blob/master/test/simple/test-buffer.js )
Tests run in Chrome 19.0.1084.52 m. May not all tests can be fixed...
I tried to omit duplicate errors.
This are the results:
TypeError: Object #<error> has no method 'copy'
at Buffer.copy (buffer-browserify/index.js:598:22)
AssertionError: "hello world" == "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
writing and reading via buffer[number]
does not work. This causes that error. (and that in L207)
Error: Unknown encoding
at Function.byteLength (buffer-browserify/index.js:58:13)
at new Buffer (buffer-browserify/index.js:323:30)
Encodings: 'ucs2', 'utf-16le', 'binary'
the base64 decoder should ignores whitespace and illegal chars.
Invalid string. Length must be a multiple of 4
https://github.com/beatgammit/base64-js/blob/master/lib/b64.js#L10 should throw an Error not a string!
Invalid string. Length must be a multiple of 4
TypeError: Object #<error> has no method 'binarySlice'
at Buffer.toString (buffer-browserify/index.js:512:26)
TypeError: Object #<error> has no method 'fill'
at Buffer.fill (buffer-browserify/index.js:558:22)
Causing zlib-browserify to be broken: brianloveswords/zlib-browserify#6
To produce the issue:
browserify test.js >out.js
debugger
statement like this: debugger
a.C = l[k++];
a.D = l[k++];
(31 !== a.C || 139 !== a.D) && m(Error("invalid file signature:", a.C, a.D));
You will notice that l
is a Buffer
and l[0]
is yielding undefined
when it should yield 31. Note also that l.parent[0]
works.
I opened this issue in the browserify project because that's where the larger community issue exists, but that depends on this project which really owns this issue.
so Buffer#fill
breaks when you call it.
I'd like to concatenate a number of buffers.
hi!
there is a strange behavior when invoking the following:
var b = new Buffer('APw', 'base64');
var r = [];
for (var i = 0; i < b.length;) {
// Calculate charcode from two adjacent bytes.
r.push(String.fromCharCode(b[i++] << 8 | b[i++]));
}
return r.join('');
on node, this returns 'ΓΌ', but in your implementation, it fails with the message:
"Invalid string. Length must be a multiple of 4", caused by require("base64-js").toByteArray ...
Is there a way around this, e.g. using the native base64 to ascii implemenations?
cheers
felix
test("hex of int16 3", function(t) {
t.plan(1);
var v1=new buffer.Buffer(2);
var v2=new Buffer(2);
v1.writeInt16BE(3,0);
v2.writeInt16BE(3,0);
t.equal(
v1.toString("hex"),
v2.toString("hex")
);
t.end();
});
This test fails. But if I change the assignments in writeUInt16 to:
if (isBigEndian) {
buffer.parent[buffer.offset+offset] = (value & 0xff00) >>> 8;
buffer.parent[buffer.offset+offset + 1] = value & 0x00ff;
} else {
buffer.parent[buffer.offset+offset + 1] = (value & 0xff00) >>> 8;
buffer.parent[buffer.offset+offset] = value & 0x00ff;
}
It seems to work. But is it this simple? Seems like the parent is not always used.
Hi!
I need slicing for a library that i am porting.
I have started to look into how to make it work. The main issue seems to me that Buffer.slice and Array.slice work in a different way. The first references to the original buffer, and modifications alter the original buffer, while the second generates a new copy.
Did you started to look into this? comments / directions are welcome!
On chrome create new buffer from object array we got difficult buffer like node.js
@toots please publish a new version.
Does this thing support ArrayBuffers/DataViews?
Any ideas?
ok 979 should be equal
ok 980 should be equal
ok 981 should be equal
ok 982 should be equal
ok 983 should be equal
ok 984 should be equal
ok 985 should be equal
ok 986 should be equal
ok 987 should be equal
not ok 988 test/buffer.js
---
exit: 143
timedOut: true
stderr: |
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at EventEmitter.addListener (events.js:160:15)
at test (/Users/feross/code/buffer-browserify/node_modules/tape/index.js:103:11)
at Object.<anonymous> (/Users/feross/code/buffer-browserify/test/buffer.js:104:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at EventEmitter.addListener (events.js:160:15)
at test (/Users/feross/code/buffer-browserify/node_modules/tape/index.js:108:11)
at Object.<anonymous> (/Users/feross/code/buffer-browserify/test/buffer.js:104:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at EventEmitter.addListener (events.js:160:15)
at test (/Users/feross/code/buffer-browserify/node_modules/tape/index.js:110:11)
at Object.<anonymous> (/Users/feross/code/buffer-browserify/test/buffer.js:104:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
command: "node" "buffer.js"
...
1..988
# tests 988
# pass 987
# fail 1
ok test/indexes.js .................................... 22/22
ok test/is-encoding.js .................................. 4/4
total ............................................. 1013/1014
not ok
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.