Skip to content

Commit fe9b6f4

Browse files
committed
feat: buffer includes
1 parent 8366a33 commit fe9b6f4

2 files changed

Lines changed: 377 additions & 4 deletions

File tree

lib/natives/buffer.js

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,67 @@
1+
class BBuffer extends Buffer {
2+
length() { }
3+
isBuffer() { }
4+
concat() { }
5+
resize() { }
6+
append() { }
7+
write() { }
8+
fill() { }
9+
indexOf() { }
10+
compare() { }
11+
copy() { }
12+
readUInt8() { }
13+
readUInt16LE() { }
14+
readUInt16BE() { }
15+
readUInt32LE() { }
16+
readUInt32BE() { }
17+
readUIntLE() { }
18+
readUIntBE() { }
19+
readInt8() { }
20+
readInt16LE() { }
21+
readInt16BE() { }
22+
readInt32LE() { }
23+
readInt32BE() { }
24+
readIntLE() { }
25+
readIntBE() { }
26+
readInt64LE() { }
27+
readInt64BE() { }
28+
readFloatLE() { }
29+
readFloatBE() { }
30+
readDoubleLE() { }
31+
readDoubleBE() { }
32+
writeUInt8() { }
33+
writeUInt16LE() { }
34+
writeUInt16BE() { }
35+
writeUInt32LE() { }
36+
writeUInt32BE() { }
37+
writeUIntLE() { }
38+
writeUIntBE() { }
39+
writeInt8() { }
40+
writeInt16LE() { }
41+
writeInt16BE() { }
42+
writeInt32LE() { }
43+
writeInt32BE() { }
44+
writeIntLE() { }
45+
writeIntBE() { }
46+
writeInt64LE() { }
47+
writeInt64BE() { }
48+
writeFloatLE() { }
49+
writeFloatBE() { }
50+
writeDoubleLE() { }
51+
writeDoubleBE() { }
52+
slice() { }
53+
hex() { }
54+
base64() { }
55+
toArray() { }
56+
toString() { }
57+
dispose() { }
58+
equals() { }
59+
toJSON() { }
60+
valueOf() { }
61+
}
62+
63+
let _proto = {};
64+
165
const buffer = {
266
kMaxLength: process.arch === 'x64' ? 0x7fffffff : 0x3fffffff,
367
kStringMaxLength: (1 << 28) - 16,// copy from v8.h
@@ -34,6 +98,7 @@ const buffer = {
3498
return byteLength;
3599
},
36100
setupBufferJS(proto, bindingObj) {
101+
_proto = proto;
37102
proto.asciiSlice = asciiSlice;
38103
proto.base64Slice = base64Slice;
39104
proto.latin1Slice = latin1Slice;
@@ -53,8 +118,14 @@ const buffer = {
53118
return new Buffer(buf1).compare(new Buffer(buf2));
54119
},
55120
compare_() { },
56-
createFromString() {
57-
121+
createFromString(string, encoding) {
122+
if ((encoding == "ucs2") || (encoding == "ucs-2") || (encoding == "utf16le")) {
123+
encoding = "utf-16le";
124+
}
125+
for (let pro in _proto) {
126+
BBuffer.prototype[pro] = _proto[pro];
127+
}
128+
return new BBuffer(string, encoding);
58129
},
59130
copy(obj, b, targetStart, sourceStart, sourceEnd) {
60131
b.set(obj, sourceStart, sourceEnd);
@@ -319,8 +390,8 @@ function indexOf(buffer, val, byteOffset, encoding, dir) {
319390
}
320391
console.log('buf111:', buf);
321392

322-
323-
393+
394+
324395
// console.log('buf222:', buffer.toString('hex'));
325396
// if (byteOffset < 0) {
326397
// byteOffset = -byteOffset;

0 commit comments

Comments
 (0)