Skip to content

Commit d39c1ab

Browse files
committed
Fixes for node.js deprecation DEP0005 new Buffer()
1 parent 8aaca47 commit d39c1ab

File tree

12 files changed

+152
-74
lines changed

12 files changed

+152
-74
lines changed

database-jones/Adapter/common/MySQLSerialize.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function Binary(type, jsValue, buffer) {
100100
size ::= uint16 | uint32
101101
*/
102102
Binary.prototype.writeHeader = function(count, size) {
103-
var buffer = new Buffer(this.isLarge ? 8 : 4);
103+
var buffer = Buffer.alloc(this.isLarge ? 8 : 4);
104104
if(this.isLarge) {
105105
buffer.writeUInt32LE(count, 0);
106106
buffer.writeUInt32LE(size, 4);
@@ -160,7 +160,7 @@ Binary.prototype.setLarge = function() {
160160

161161
Binary.prototype.write = function() {
162162
return this.isUndefined ? null :
163-
Buffer.concat([new Buffer([this.type]), this.buffer], this.buffer.length+1);
163+
Buffer.concat([Buffer.from([this.type]), this.buffer], this.buffer.length+1);
164164
};
165165

166166

@@ -197,7 +197,7 @@ VariableLength.prototype.serialize = function() {
197197
lengthArray.push(byte);
198198
} while(length);
199199

200-
return new Buffer(lengthArray);
200+
return Buffer.from(lengthArray);
201201
};
202202

203203

@@ -206,21 +206,21 @@ function serializeString(jsString) {
206206
var stringBuffer, lengthBuffer, binary, vlen;
207207

208208
binary = new Binary(TYPE_STRING, jsString);
209-
stringBuffer = new Buffer(jsString, 'utf8');
209+
stringBuffer = Buffer.from(jsString, 'utf8');
210210
vlen = new VariableLength(stringBuffer.length);
211211
lengthBuffer = vlen.serialize();
212212
binary.buffer = Buffer.concat([ lengthBuffer, stringBuffer ]);
213213
return binary;
214214
}
215215

216216
function serializeDouble(jsNumber) {
217-
var binary = new Binary(TYPE_DOUBLE, jsNumber, new Buffer(8));
217+
var binary = new Binary(TYPE_DOUBLE, jsNumber, Buffer.alloc(8));
218218
binary.buffer.writeDoubleLE(jsNumber, 0);
219219
return binary;
220220
}
221221

222222
function serializeInt16(jsNumber) {
223-
var binary = new Binary(TYPE_INT16, jsNumber, new Buffer(2));
223+
var binary = new Binary(TYPE_INT16, jsNumber, Buffer.alloc(2));
224224
if(jsNumber < 32768) {
225225
binary.buffer.writeInt16LE(jsNumber, 0);
226226
} else {
@@ -231,7 +231,7 @@ function serializeInt16(jsNumber) {
231231
}
232232

233233
function serializeInt32(jsNumber) {
234-
var binary = new Binary(TYPE_INT32, jsNumber, new Buffer(4));
234+
var binary = new Binary(TYPE_INT32, jsNumber, Buffer.alloc(4));
235235
if(jsNumber < 2147483648) {
236236
binary.buffer.writeInt32LE(jsNumber, 0);
237237
} else {
@@ -243,7 +243,7 @@ function serializeInt32(jsNumber) {
243243

244244
function serializeInt64(jsNumber) {
245245
var binary = new Binary(TYPE_INT64, jsNumber);
246-
binary.buffer = new Buffer([0,0,0,0, 0,0,0,0]);
246+
binary.buffer = Buffer.from([0,0,0,0, 0,0,0,0]);
247247
if(jsNumber < 0) {
248248
assert.ifError("Encoding of large negative values is not implemented");
249249
} else {
@@ -350,7 +350,7 @@ function List(binary, entrySizeArray, itemConstructor, dataBuffer) {
350350
this.entrySize = entrySizeArray[this.parent.type];
351351
this.ItemConstructor = itemConstructor;
352352
this.entries = [];
353-
this.data = dataBuffer || new Buffer("");
353+
this.data = dataBuffer || Buffer.from("");
354354
}
355355

356356
List.prototype.push = function(binaryForm) {
@@ -363,7 +363,7 @@ List.prototype.writeEntries = function(dataStartPos) {
363363
var buffer, elemSize, cursor, isLarge;
364364

365365
elemSize = this.entrySize;
366-
buffer = new Buffer(this.entries.length * elemSize);
366+
buffer = Buffer.alloc(this.entries.length * elemSize);
367367
cursor = 0;
368368
isLarge = this.parent.isLarge;
369369

@@ -448,7 +448,7 @@ function sortKeys(a,b) {
448448

449449
/* key ::= utf8-data */
450450
function serializeKey(jsString) {
451-
return new Binary(BINARY_KEY, jsString, new Buffer(jsString, 'utf8'));
451+
return new Binary(BINARY_KEY, jsString, Buffer.from(jsString, 'utf8'));
452452
}
453453

454454
function serializeObject(jsObject) {
@@ -509,9 +509,9 @@ function serializeObject(jsObject) {
509509

510510

511511
/* Some pre-fabricated Binary values */
512-
binaryNull = new Binary(TYPE_LITERAL, null, new Buffer( [LITERAL_NULL] ));
513-
binaryTrue = new Binary(TYPE_LITERAL, true, new Buffer( [LITERAL_TRUE] ));
514-
binaryFalse = new Binary(TYPE_LITERAL, false, new Buffer( [LITERAL_FALSE] ));
512+
binaryNull = new Binary(TYPE_LITERAL, null, Buffer.from( [LITERAL_NULL] ));
513+
binaryTrue = new Binary(TYPE_LITERAL, true, Buffer.from( [LITERAL_TRUE] ));
514+
binaryFalse = new Binary(TYPE_LITERAL, false, Buffer.from( [LITERAL_FALSE] ));
515515
binaryUndefined = new Binary(TYPE_LITERAL);
516516

517517

database-jones/package-lock.json

+81
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

database-jones/package.json

+31-34
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
1-
21
{
3-
"name" : "database-jones"
4-
,
5-
"version" : "1.2.7"
6-
,
7-
"description" : "Lightweight database mapping"
8-
,
9-
"keywords" : ["mysql", "orm", "ndb", "mapping" ]
10-
,
11-
"homepage" : "http://github.com/mysql/mysql-js/"
12-
,
13-
"bugs" : { "url" : "http://github.com/mysql/mysql-js/issues"
14-
}
15-
,
16-
"license" : "GPL-2.0"
17-
,
18-
"contributors" : [ "Craig Russell <papajdo@gmail.com>" ,
19-
"John David Duncan <john.duncan@oracle.com>"
20-
]
21-
,
22-
"main" : "Adapter/api/jones"
23-
,
24-
"repository" : { "type" : "git",
25-
"url": "https://github.com/mysql/mysql-js.git"
26-
}
27-
,
28-
"dependencies" : { "jones-promises" : "*",
29-
"unified_debug" : "*"
30-
}
31-
,
32-
"devDependencies" : { "jones-test" : "*"
33-
}
2+
"name": "database-jones",
3+
"version": "1.2.7",
4+
"description": "Lightweight database mapping",
5+
"keywords": [
6+
"mysql",
7+
"orm",
8+
"ndb",
9+
"mapping"
10+
],
11+
"homepage": "http://github.com/mysql/mysql-js/",
12+
"bugs": {
13+
"url": "http://github.com/mysql/mysql-js/issues"
14+
},
15+
"license": "GPL-2.0",
16+
"contributors": [
17+
"Craig Russell <papajdo@gmail.com>",
18+
"John David Duncan <john.duncan@oracle.com>"
19+
],
20+
"main": "Adapter/api/jones",
21+
"repository": {
22+
"type": "git",
23+
"url": "https://github.com/mysql/mysql-js.git"
24+
},
25+
"dependencies": {
26+
"jones-promises": "*",
27+
"mysql": "^2.17.1",
28+
"unified_debug": "*"
29+
},
30+
"devDependencies": {
31+
"jones-test": "*"
32+
}
3433
}
35-
36-

jones-mysql/test/stringtypes/BinaryTest.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var t1 = new harness.ConcurrentTest("t1:binary_full_length");
5656
t1.run = function() {
5757
var data, value, i;
5858
data = new TestData();
59-
value = new Buffer(20);
59+
value = Buffer.alloc(20);
6060
for(i = 0 ; i < 20 ; i ++) {
6161
value[i] = i;
6262
}
@@ -70,8 +70,8 @@ var t2 = new harness.ConcurrentTest("t2:binary_zero_padded");
7070
t2.run = function() {
7171
var data, value, expected;
7272
data = new TestData();
73-
value = new Buffer([1,2,3,4,5,6,7,8,9,10]);
74-
expected = new Buffer([1,2,3,4,5,6,7,8,9,10,0,0,0,0,0,0,0,0,0,0]);
73+
value = Buffer.from([1,2,3,4,5,6,7,8,9,10]);
74+
expected = Buffer.from([1,2,3,4,5,6,7,8,9,10,0,0,0,0,0,0,0,0,0,0]);
7575

7676
data.bin_fix = value;
7777
this.verifier = new BufferVerifier(this, "bin_fix", expected);
@@ -82,7 +82,7 @@ var t3 = new harness.ConcurrentTest("t3:varbinary");
8282
t3.run = function() {
8383
var data, value, i;
8484
data = new TestData();
85-
value = new Buffer(120);
85+
value = Buffer.alloc(120);
8686
for(i = 0 ; i < 120 ; i ++) {
8787
value[i] = i;
8888
}
@@ -96,7 +96,7 @@ var t4 = new harness.ConcurrentTest("t4:longvarbinary");
9696
t4.run = function() {
9797
var data, value, i;
9898
data = new TestData();
99-
value = new Buffer(320);
99+
value = Buffer.alloc(320);
100100
for(i = 0 ; i < 320 ; i ++) {
101101
value[i] = 32 + (i % 90);
102102
}
@@ -126,7 +126,7 @@ t5.run = function() {
126126
var t6 = new harness.ConcurrentTest("t6:InsertBLOB");
127127
t6.run = function() {
128128
var data = new TestData();
129-
data.bin_lob = new Buffer(20000);
129+
data.bin_lob = Buffer.alloc(20000);
130130
fail_openSession(this, function(session, testCase) {
131131
session.persist(data, function(err) {
132132
testCase.errorIfError(err);
@@ -157,7 +157,7 @@ var t8 = new harness.ConcurrentTest("t8:WriteAndReadBlob");
157157
t8.run = function() {
158158
var data, value, i;
159159
data = new TestData();
160-
value = new Buffer(20000);
160+
value = Buffer.alloc(20000);
161161
for(i = 0 ; i < 20000 ; i++) {
162162
value[i] = Math.ceil(Math.random() * 256);
163163
}
@@ -170,8 +170,8 @@ var t9 = new harness.ConcurrentTest("t9:ReadModifyUpdate");
170170
t9.run = function() {
171171
var data, value1, value2, i;
172172
data = new TestData();
173-
value1 = new Buffer(320);
174-
value2 = new Buffer(320);
173+
value1 = Buffer.alloc(320);
174+
value2 = Buffer.alloc(320);
175175
for(i = 0 ; i < 320 ; i ++) {
176176
value1[i] = 32 + (i % 90);
177177
value2[i] = 119 - (i % 80);

jones-mysql/test/stringtypes/TextTest.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var t1 = new harness.ConcurrentTest("t1:WriteAndReadBlob");
4747
t1.run = function() {
4848
var data, value, i, verifier;
4949
data = new TextBlobData();
50-
value = new Buffer(20000);
50+
value = Buffer.alloc(20000);
5151
for(i = 0 ; i < 20000 ; i++) {
5252
value[i] = Math.ceil(Math.random() * 256);
5353
}
@@ -79,7 +79,7 @@ t2.run = function() {
7979
var t3 = new harness.ConcurrentTest("t3:TextAndBlob");
8080
t3.run = function() {
8181
var data = new TextBlobData();
82-
data.blob_col = new Buffer([1,2,3,4,5,6,7,8,9,10,90,89,88,87,86,85,84]);
82+
data.blob_col = Buffer.from([1,2,3,4,5,6,7,8,9,10,90,89,88,87,86,85,84]);
8383
data.text_col = "// {{ ?? }} \\";
8484
fail_openSession(this, function(session, testCase) {
8585
session.persist(data, function(err) {

jones-ndb/impl/ndb/NdbOperation.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ var DBOperation = function(opcode, tx, indexHandler, tableHandler) {
206206

207207
function allocateKeyBuffer(op) {
208208
assert(op.buffers.key === null);
209-
op.buffers.key = new Buffer(op.index.record.getBufferSize());
209+
op.buffers.key = Buffer.alloc(op.index.record.getBufferSize());
210210
}
211211

212212
function releaseKeyBuffer(op) {
@@ -281,7 +281,7 @@ function defineBlobs(ncolumns, metadata, values) {
281281

282282
function allocateRowBuffer(op) {
283283
assert(op.buffers.row === null);
284-
op.buffers.row = new Buffer(op.tableHandler.resultRecord.getBufferSize());
284+
op.buffers.row = Buffer.alloc(op.tableHandler.resultRecord.getBufferSize());
285285
}
286286

287287
function releaseRowBuffer(op) {
@@ -406,7 +406,7 @@ DBOperation.prototype.buildBoundHelpers = function(indexBounds) {
406406
n = indexBounds.length;
407407
if(sz && n) {
408408
allHelpers = [];
409-
mainBuffer = new Buffer(sz * n * 2);
409+
mainBuffer = Buffer.alloc(sz * n * 2);
410410
offset = 0;
411411
this.scan.bound_param_buffer = mainBuffer; // maintain a reference!
412412
for(i = 0 ; i < n ; i++) {
@@ -672,7 +672,7 @@ function getScanResults(scanop, userCallback) {
672672
}
673673

674674
function fetch() {
675-
buffer = new Buffer(recordSize);
675+
buffer = Buffer.alloc(recordSize);
676676
fetchResults(dbSession, scanop.scanOp, buffer); // gather() is the callback
677677
}
678678

@@ -690,7 +690,7 @@ function getScanResults(scanop, userCallback) {
690690
/* Gather more results. */
691691
while(status === 0 && results.length < maxRow) {
692692
pushNewResult();
693-
buffer = new Buffer(recordSize);
693+
buffer = Buffer.alloc(recordSize);
694694
status = scanop.scanOp.nextResult(buffer);
695695
}
696696

jones-ndb/impl/ndb/NdbScanFilter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ BufferSchema.prototype.encode = function(params) {
7373
buffer = null;
7474

7575
if(this.size > 0) {
76-
buffer = new Buffer(this.size);
76+
buffer = Buffer.alloc(this.size);
7777
for(i = 0; i < this.layout.length ; i++) {
7878
this.layout[i].encode(buffer, params);
7979
}

0 commit comments

Comments
 (0)