buffer: add constants with max buffer and string lengths by addaleax · Pull Request #13467 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 49 additions & 12 deletions doc/api/buffer.md
23 changes: 23 additions & 0 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,31 @@ Buffer.prototype = FastBuffer.prototype;
exports.Buffer = Buffer;
exports.SlowBuffer = SlowBuffer;
exports.INSPECT_MAX_BYTES = 50;

// Legacy.
exports.kMaxLength = binding.kMaxLength;

const constants = Object.defineProperties({}, {
MAX_LENGTH: {
value: binding.kStringMaxLength,
writable: false,
enumerable: true
},
MAX_STRING_LENGTH: {
value: binding.kStringMaxLength,
writable: false,
enumerable: true
}
});

Object.defineProperty(exports, 'constants', {
configurable: false,
enumerable: true,
value: constants
});

exports.kStringMaxLength = binding.kStringMaxLength;

const kFromErrorMsg = 'First argument must be a string, Buffer, ' +
'ArrayBuffer, Array, or array-like object.';

Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-buffer-constants.js