Skip to content

Commit a3753b4

Browse files
committed
Revert "Fix nodejs#3242 Actually deprecate 'binary' buffer encoding"
This reverts commit 5979f09. Related: - nodejs#3279 - nodejs#3278
1 parent 9fc7283 commit a3753b4

3 files changed

Lines changed: 12 additions & 30 deletions

File tree

doc/api/buffer.markdown

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ encoding method. Here are the different string encodings.
3333

3434
* `'base64'` - Base64 string encoding.
3535

36-
* `'hex'` - Encode each byte as two hexadecimal characters.
36+
* `'binary'` - A way of encoding raw binary data into strings by using only
37+
the first 8 bits of each character. This encoding method is deprecated and
38+
should be avoided in favor of `Buffer` objects where possible. This encoding
39+
will be removed in future versions of Node.
3740

38-
If you need direct access to the bytes, then the best way is to use a
39-
Buffer object directly, rather than any string encoding. In the past,
40-
there were options for `'binary'`, `'raw'`, and others, but these all
41-
involve unnecessary copying. Just use Buffers directly if you need
42-
access to the actual bytes.
41+
* `'hex'` - Encode each byte as two hexadecimal characters.
4342

4443
## Class: Buffer
4544

lib/buffer.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@
2222
var SlowBuffer = process.binding('buffer').SlowBuffer;
2323
var assert = require('assert');
2424

25-
// Deprecate the 'binary' encoding.
26-
// TODO: Remove it entirely in v0.9.
27-
var binaryWarned = false;
28-
function binaryWarn() {
29-
if (binaryWarned) return;
30-
binaryWarned = true;
31-
console.error('The binary buffer encoding is deprecated.');
32-
}
33-
3425
exports.INSPECT_MAX_BYTES = 50;
3526

3627
// Make SlowBuffer inherit from Buffer.
@@ -81,7 +72,6 @@ SlowBuffer.prototype.toString = function(encoding, start, end) {
8172
return this.asciiSlice(start, end);
8273

8374
case 'binary':
84-
binaryWarn();
8575
return this.binarySlice(start, end);
8676

8777
case 'base64':
@@ -168,7 +158,6 @@ SlowBuffer.prototype.write = function(string, offset, length, encoding) {
168158
return this.asciiWrite(string, offset, length);
169159

170160
case 'binary':
171-
binaryWarn();
172161
return this.binaryWrite(string, offset, length);
173162

174163
case 'base64':
@@ -370,7 +359,6 @@ Buffer.prototype.write = function(string, offset, length, encoding) {
370359
break;
371360

372361
case 'binary':
373-
binaryWarn();
374362
ret = this.parent.binaryWrite(string, this.offset + offset, length);
375363
break;
376364

@@ -427,7 +415,6 @@ Buffer.prototype.toString = function(encoding, start, end) {
427415
return this.parent.asciiSlice(start, end);
428416

429417
case 'binary':
430-
binaryWarn();
431418
return this.parent.binarySlice(start, end);
432419

433420
case 'base64':
@@ -540,7 +527,6 @@ Buffer.prototype.utf8Slice = function(start, end) {
540527
};
541528

542529
Buffer.prototype.binarySlice = function(start, end) {
543-
binaryWarn();
544530
return this.toString('binary', start, end);
545531
};
546532

@@ -553,7 +539,6 @@ Buffer.prototype.utf8Write = function(string, offset) {
553539
};
554540

555541
Buffer.prototype.binaryWrite = function(string, offset) {
556-
binaryWarn();
557542
return this.write(string, offset, 'binary');
558543
};
559544

src/node.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,18 +1111,16 @@ enum encoding ParseEncoding(Handle<Value> encoding_v, enum encoding _default) {
11111111
} else if (strcasecmp(*encoding, "ucs-2") == 0) {
11121112
return UCS2;
11131113
} else if (strcasecmp(*encoding, "binary") == 0) {
1114-
fprintf(stderr, "The 'binary' buffer encoding is deprecated. "
1115-
"Use a Buffer object directly.\n");
11161114
return BINARY;
11171115
} else if (strcasecmp(*encoding, "hex") == 0) {
11181116
return HEX;
11191117
} else if (strcasecmp(*encoding, "raw") == 0) {
11201118
fprintf(stderr, "'raw' (array of integers) has been removed. "
1121-
"Use a Buffer object directly.\n");
1119+
"Use 'binary'.\n");
11221120
return BINARY;
11231121
} else if (strcasecmp(*encoding, "raws") == 0) {
1124-
fprintf(stderr, "'raws' (array of integers) has been removed. "
1125-
"Use a Buffer object directly.\n");
1122+
fprintf(stderr, "'raws' encoding has been renamed to 'binary'. "
1123+
"Please update your code.\n");
11261124
return BINARY;
11271125
} else {
11281126
return _default;
@@ -1156,8 +1154,8 @@ ssize_t DecodeBytes(v8::Handle<v8::Value> val, enum encoding encoding) {
11561154
HandleScope scope;
11571155

11581156
if (val->IsArray()) {
1159-
fprintf(stderr, "'raw' (array of integers) has been removed. "
1160-
"Use a Buffer object directly.\n");
1157+
fprintf(stderr, "'raw' encoding (array of integers) has been removed. "
1158+
"Use 'binary'.\n");
11611159
assert(0);
11621160
return -1;
11631161
}
@@ -1193,8 +1191,8 @@ ssize_t DecodeWrite(char *buf,
11931191
// http://groups.google.com/group/v8-users/browse_thread/thread/1f83b0ba1f0a611
11941192

11951193
if (val->IsArray()) {
1196-
fprintf(stderr, "'raw' (array of integers) has been removed. "
1197-
"Use a Buffer object directly.\n");
1194+
fprintf(stderr, "'raw' encoding (array of integers) has been removed. "
1195+
"Use 'binary'.\n");
11981196
assert(0);
11991197
return -1;
12001198
}

0 commit comments

Comments
 (0)