Skip to content

Commit b87669c

Browse files
committed
Fix fastbuffer style
Fix style
1 parent 2b07c9f commit b87669c

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

lib/buffer.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
var SlowBuffer = process.binding('buffer').Buffer;
22

3+
34
function toHex (n) {
45
if (n < 16) return "0" + n.toString(16);
56
return n.toString(16);
67
}
78

8-
SlowBuffer.isSlowBuffer = function (b) {
9-
return b instanceof SlowBuffer;
10-
};
119

1210
SlowBuffer.prototype.inspect = function () {
1311
var out = [],
@@ -18,6 +16,7 @@ SlowBuffer.prototype.inspect = function () {
1816
return "<SlowBuffer " + out.join(" ") + ">";
1917
};
2018

19+
2120
SlowBuffer.prototype.toString = function (encoding, start, stop) {
2221
encoding = String(encoding || 'utf8').toLowerCase();
2322
start = +start || 0;
@@ -47,6 +46,7 @@ SlowBuffer.prototype.toString = function (encoding, start, stop) {
4746
}
4847
};
4948

49+
5050
SlowBuffer.prototype.write = function (string, offset, encoding) {
5151
// Support both (string, offset, encoding)
5252
// and the legacy (string, encoding, offset)
@@ -78,23 +78,18 @@ SlowBuffer.prototype.write = function (string, offset, encoding) {
7878
}
7979
};
8080

81-
SlowBuffer.prototype.get = function (index) {
82-
return this[index];
83-
};
84-
85-
SlowBuffer.prototype.set = function (index, value) {
86-
return this[index] = value;
87-
};
8881

8982
// Buffer
9083
var POOLSIZE = 8*1024;
9184
var pool;
9285

86+
9387
function allocPool () {
9488
pool = new SlowBuffer(POOLSIZE);
9589
pool.used = 0;
9690
}
9791

92+
9893
function Buffer (subject, encoding, legacy, slice_legacy) {
9994
var length, type;
10095

@@ -157,11 +152,13 @@ function Buffer (subject, encoding, legacy, slice_legacy) {
157152

158153
exports.Buffer = Buffer;
159154

155+
160156
// Static methods
161157
Buffer.isBuffer = function isBuffer(b) {
162158
return b instanceof Buffer;
163159
};
164160

161+
165162
// Inspect
166163
Buffer.prototype.inspect = function inspect() {
167164
var out = [],
@@ -172,18 +169,18 @@ Buffer.prototype.inspect = function inspect() {
172169
return "<Buffer " + out.join(" ") + ">";
173170
};
174171

172+
175173
Buffer.prototype.get = function get (i) {
176174
if (i < 0 || i >= this.length) throw new Error("oob");
177175
return this.parent[this.offset + i];
178176
};
179177

178+
180179
Buffer.prototype.set = function set (i, v) {
181180
if (i < 0 || i >= this.length) throw new Error("oob");
182181
return this.parent[this.offset + i] = v;
183182
};
184183

185-
// TODO define slice, toString, write, etc.
186-
// slice should not use c++
187184

188185
// write(string, offset = 0, encoding = 'uft8')
189186
Buffer.prototype.write = function write (string, offset, encoding) {
@@ -193,18 +190,18 @@ Buffer.prototype.write = function write (string, offset, encoding) {
193190
offset = swap;
194191
}
195192

196-
var max_length;
197193
offset || (offset = 0);
198194
encoding || (encoding = 'uft8');
199195

200196
// Make sure we are not going to overflow
201-
max_length = this.length - offset;
197+
var max_length = this.length - offset;
202198
if (string.length > max_length) {
203199
string = string.slice(0, max_length);
204200
}
205201

206202
return this.parent.write(string, this.offset + offset, encoding);
207-
}
203+
};
204+
208205

209206
// toString(encoding, start=0, end=buffer.length)
210207
Buffer.prototype.toString = function toString (encoding, start, end) {
@@ -220,9 +217,11 @@ Buffer.prototype.toString = function toString (encoding, start, end) {
220217
return this.parent.toString(encoding, start + this.offset, end + this.offset);
221218
};
222219

220+
223221
// byteLength
224222
Buffer.byteLength = SlowBuffer.byteLength;
225223

224+
226225
// copy(targetBuffer, targetStart, sourceStart, sourceEnd=buffer.length)
227226
Buffer.prototype.copy = function copy (target, target_start, start, end) {
228227
start || (start = 0);
@@ -233,11 +232,15 @@ Buffer.prototype.copy = function copy (target, target_start, start, end) {
233232
end = this.length;
234233
}
235234

236-
return this.parent.copy(target.parent, target_start + target.offset, start + this.offset, end + this.offset);
235+
return this.parent.copy(target.parent,
236+
target_start + target.offset,
237+
start + this.offset,
238+
end + this.offset);
237239
};
238240

241+
239242
// slice(start, end)
240-
Buffer.prototype.slice = function slice (start, end, legacy) {
243+
Buffer.prototype.slice = function (start, end, legacy) {
241244
if (end > this.length) {
242245
throw new Error("oob");
243246
}
@@ -247,3 +250,4 @@ Buffer.prototype.slice = function slice (start, end, legacy) {
247250

248251
return new Buffer(this.parent, end - start, +start + this.offset, legacy);
249252
};
253+

0 commit comments

Comments
 (0)