Skip to content

Commit 487e409

Browse files
committed
Re-arrange the modules to keep backwards compatibility with master.
Mutable buffers are now the default again, and immutable buffers are moved to Node.Buffer.Immutable
1 parent a71708d commit 487e409

File tree

11 files changed

+837
-828
lines changed

11 files changed

+837
-828
lines changed

src/Node/Buffer.js

Lines changed: 46 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,74 @@
11
/* global exports */
22
/* global Buffer */
3-
/* global require */
43
"use strict";
54

6-
exports.showImpl = require('util').inspect;
7-
8-
exports.eqImpl = function(a) {
9-
return function(b) {
10-
return a.equals(b);
11-
}
12-
};
13-
14-
exports.compareImpl = function(a) {
15-
return function (b) {
16-
return a.compare(b);
5+
exports.copyAllImpl = function(a) {
6+
return function() {
7+
return Buffer.from(a);
178
};
18-
}
19-
20-
exports.create = function (size) {
21-
return Buffer.alloc(size);
22-
};
23-
24-
exports.fromArray = function (octets) {
25-
return Buffer.from(octets);
26-
};
27-
28-
exports.size = function (buff) {
29-
return buff.length;
30-
};
31-
32-
exports.toArray = function (buff) {
33-
var json = buff.toJSON()
34-
return json.data || json;
35-
};
36-
37-
exports.toArrayBuffer = function(buff) {
38-
return buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength);
39-
};
40-
41-
exports.fromArrayBuffer = function(ab) {
42-
return Buffer.from(ab);
439
};
4410

45-
exports.fromStringImpl = function (str) {
46-
return function (encoding) {
47-
return Buffer.from(str, encoding);
11+
exports.writeInternal = function (ty) {
12+
return function (value) {
13+
return function (offset) {
14+
return function (buf) {
15+
return function() {
16+
buf['write' + ty](value, offset);
17+
return {};
18+
}
19+
};
20+
};
4821
};
4922
};
5023

51-
exports.readImpl = function (ty) {
24+
exports.writeStringInternal = function (encoding) {
5225
return function (offset) {
53-
return function (buf) {
54-
return buf['read' + ty](offset);
26+
return function (length) {
27+
return function (value) {
28+
return function (buff) {
29+
return function() {
30+
return buff.write(value, offset, length, encoding);
31+
}
32+
};
33+
};
5534
};
5635
};
5736
};
5837

59-
exports.readStringImpl = function (enc) {
60-
return function (start) {
61-
return function (end) {
62-
return function (buff) {
63-
return buff.toString(enc, start, end);
38+
exports.setAtOffsetImpl = function (value) {
39+
return function (offset) {
40+
return function (buff) {
41+
return function() {
42+
buff[offset] = value;
43+
return {};
6444
};
6545
};
6646
};
6747
};
6848

69-
exports.getAtOffsetImpl = function (just) {
70-
return function (nothing) {
71-
return function (offset) {
72-
return function (buff) {
73-
var octet = buff[offset];
74-
return octet == null ? nothing
75-
: just(octet);
49+
exports.copyImpl = function (srcStart) {
50+
return function (srcEnd) {
51+
return function (src) {
52+
return function (targStart) {
53+
return function (targ) {
54+
return function() {
55+
return src.copy(targ, targStart, srcStart, srcEnd);
56+
};
57+
};
7658
};
7759
};
7860
};
7961
};
8062

81-
exports.toStringImpl = function (enc) {
82-
return function (buff) {
83-
return buff.toString(enc);
84-
};
85-
};
86-
87-
exports.slice = function (start) {
88-
return function (end) {
89-
return function (buff) {
90-
return buff.slice(start, end);
63+
exports.fillImpl = function (octet) {
64+
return function (start) {
65+
return function (end) {
66+
return function (buf) {
67+
return function() {
68+
buf.fill(octet, start, end);
69+
return {};
70+
};
71+
};
9172
};
9273
};
9374
};
94-
95-
exports.concat = function (buffs) {
96-
return Buffer.concat(buffs);
97-
};
98-
99-
exports["concat'"] = function (buffs) {
100-
return function (totalLength) {
101-
return Buffer.concat(buffs, totalLength);
102-
};
103-
};

0 commit comments

Comments
 (0)