Skip to content

Commit aa03625

Browse files
committed
Add cloning buffers.
1 parent 418e73f commit aa03625

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- updated: `UNINSTALL(type, url/id/fn)` supports new types `web`, `websocket` and `file`, e.g. `UNINSTALL('web', 'id:custom_identificator')`
2020
- updated: `U.request()`, added a new flag: `raw` (sends raw data)
2121
- updated: `F.schedule()` returns an identificator
22+
- updated: `U.clone()` supports `buffer` properties
2223

2324
- fixed: routing with `upload` flag
2425
- fixed: workers timeout

test/test-utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ function other() {
642642

643643
streamer(Buffer.from('aaaa <a>1</a> adsklasdlajsdlas jd <a>2</a>'));
644644
streamer(Buffer.from('aaaa <a>3</a> adsklasdlajsdlas jd <a>4</a>'));
645+
646+
var a = { buf: Buffer.from('123456') };
647+
assert.ok(U.clone(a).buf !== a, 'Cloning buffers');
648+
645649
}
646650

647651
function onValidation(name, value, path) {

utils.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,14 @@ exports.clone = function(obj, skip, skipFunctions) {
12751275
continue;
12761276

12771277
var val = obj[m];
1278+
1279+
if (val instanceof Buffer) {
1280+
var copy = exports.createBufferSize(val.length);
1281+
val.copy(copy);
1282+
o[m] = copy;
1283+
continue;
1284+
}
1285+
12781286
var type = typeof(val);
12791287
if (type !== 'object' || val instanceof Date) {
12801288
if (skipFunctions && type === 'function')
@@ -1308,8 +1316,7 @@ exports.copy = function(source, target) {
13081316

13091317
while (i--) {
13101318
var key = keys[i];
1311-
if (target[key] !== undefined)
1312-
target[key] = exports.clone(source[key]);
1319+
target[key] !== undefined && (target[key] = exports.clone(source[key]));
13131320
}
13141321

13151322
return target;

0 commit comments

Comments
 (0)