Revert "Fix #3242 Actually deprecate 'binary' buffer encoding"

This reverts commit 5979f096d1b702ca2ba95664a0bbc8210109775b.

Related:
- #3279
- #3278
This commit is contained in:
isaacs 2012-05-16 16:32:37 -07:00
parent 9fc7283a40
commit a3753b496e
3 changed files with 12 additions and 30 deletions

View File

@ -33,13 +33,12 @@ encoding method. Here are the different string encodings.
* `'base64'` - Base64 string encoding. * `'base64'` - Base64 string encoding.
* `'hex'` - Encode each byte as two hexadecimal characters. * `'binary'` - A way of encoding raw binary data into strings by using only
the first 8 bits of each character. This encoding method is deprecated and
should be avoided in favor of `Buffer` objects where possible. This encoding
will be removed in future versions of Node.
If you need direct access to the bytes, then the best way is to use a * `'hex'` - Encode each byte as two hexadecimal characters.
Buffer object directly, rather than any string encoding. In the past,
there were options for `'binary'`, `'raw'`, and others, but these all
involve unnecessary copying. Just use Buffers directly if you need
access to the actual bytes.
## Class: Buffer ## Class: Buffer

View File

@ -22,15 +22,6 @@
var SlowBuffer = process.binding('buffer').SlowBuffer; var SlowBuffer = process.binding('buffer').SlowBuffer;
var assert = require('assert'); var assert = require('assert');
// Deprecate the 'binary' encoding.
// TODO: Remove it entirely in v0.9.
var binaryWarned = false;
function binaryWarn() {
if (binaryWarned) return;
binaryWarned = true;
console.error('The binary buffer encoding is deprecated.');
}
exports.INSPECT_MAX_BYTES = 50; exports.INSPECT_MAX_BYTES = 50;
// Make SlowBuffer inherit from Buffer. // Make SlowBuffer inherit from Buffer.
@ -81,7 +72,6 @@ SlowBuffer.prototype.toString = function(encoding, start, end) {
return this.asciiSlice(start, end); return this.asciiSlice(start, end);
case 'binary': case 'binary':
binaryWarn();
return this.binarySlice(start, end); return this.binarySlice(start, end);
case 'base64': case 'base64':
@ -168,7 +158,6 @@ SlowBuffer.prototype.write = function(string, offset, length, encoding) {
return this.asciiWrite(string, offset, length); return this.asciiWrite(string, offset, length);
case 'binary': case 'binary':
binaryWarn();
return this.binaryWrite(string, offset, length); return this.binaryWrite(string, offset, length);
case 'base64': case 'base64':
@ -370,7 +359,6 @@ Buffer.prototype.write = function(string, offset, length, encoding) {
break; break;
case 'binary': case 'binary':
binaryWarn();
ret = this.parent.binaryWrite(string, this.offset + offset, length); ret = this.parent.binaryWrite(string, this.offset + offset, length);
break; break;
@ -427,7 +415,6 @@ Buffer.prototype.toString = function(encoding, start, end) {
return this.parent.asciiSlice(start, end); return this.parent.asciiSlice(start, end);
case 'binary': case 'binary':
binaryWarn();
return this.parent.binarySlice(start, end); return this.parent.binarySlice(start, end);
case 'base64': case 'base64':
@ -540,7 +527,6 @@ Buffer.prototype.utf8Slice = function(start, end) {
}; };
Buffer.prototype.binarySlice = function(start, end) { Buffer.prototype.binarySlice = function(start, end) {
binaryWarn();
return this.toString('binary', start, end); return this.toString('binary', start, end);
}; };
@ -553,7 +539,6 @@ Buffer.prototype.utf8Write = function(string, offset) {
}; };
Buffer.prototype.binaryWrite = function(string, offset) { Buffer.prototype.binaryWrite = function(string, offset) {
binaryWarn();
return this.write(string, offset, 'binary'); return this.write(string, offset, 'binary');
}; };

View File

@ -1111,18 +1111,16 @@ enum encoding ParseEncoding(Handle<Value> encoding_v, enum encoding _default) {
} else if (strcasecmp(*encoding, "ucs-2") == 0) { } else if (strcasecmp(*encoding, "ucs-2") == 0) {
return UCS2; return UCS2;
} else if (strcasecmp(*encoding, "binary") == 0) { } else if (strcasecmp(*encoding, "binary") == 0) {
fprintf(stderr, "The 'binary' buffer encoding is deprecated. "
"Use a Buffer object directly.\n");
return BINARY; return BINARY;
} else if (strcasecmp(*encoding, "hex") == 0) { } else if (strcasecmp(*encoding, "hex") == 0) {
return HEX; return HEX;
} else if (strcasecmp(*encoding, "raw") == 0) { } else if (strcasecmp(*encoding, "raw") == 0) {
fprintf(stderr, "'raw' (array of integers) has been removed. " fprintf(stderr, "'raw' (array of integers) has been removed. "
"Use a Buffer object directly.\n"); "Use 'binary'.\n");
return BINARY; return BINARY;
} else if (strcasecmp(*encoding, "raws") == 0) { } else if (strcasecmp(*encoding, "raws") == 0) {
fprintf(stderr, "'raws' (array of integers) has been removed. " fprintf(stderr, "'raws' encoding has been renamed to 'binary'. "
"Use a Buffer object directly.\n"); "Please update your code.\n");
return BINARY; return BINARY;
} else { } else {
return _default; return _default;
@ -1156,8 +1154,8 @@ ssize_t DecodeBytes(v8::Handle<v8::Value> val, enum encoding encoding) {
HandleScope scope; HandleScope scope;
if (val->IsArray()) { if (val->IsArray()) {
fprintf(stderr, "'raw' (array of integers) has been removed. " fprintf(stderr, "'raw' encoding (array of integers) has been removed. "
"Use a Buffer object directly.\n"); "Use 'binary'.\n");
assert(0); assert(0);
return -1; return -1;
} }
@ -1193,8 +1191,8 @@ ssize_t DecodeWrite(char *buf,
// http://groups.google.com/group/v8-users/browse_thread/thread/1f83b0ba1f0a611 // http://groups.google.com/group/v8-users/browse_thread/thread/1f83b0ba1f0a611
if (val->IsArray()) { if (val->IsArray()) {
fprintf(stderr, "'raw' (array of integers) has been removed. " fprintf(stderr, "'raw' encoding (array of integers) has been removed. "
"Use a Buffer object directly.\n"); "Use 'binary'.\n");
assert(0); assert(0);
return -1; return -1;
} }