-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use native Buffer whenever available
- Loading branch information
Showing
8 changed files
with
265 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const SpecificBuffer = require('./buffer'); | ||
const buffer = require('buffer/'); | ||
|
||
// Using 32-bit implementation value from Node | ||
// https://github.com/nodejs/node/blob/main/deps/v8/include/v8-primitive.h#L126 | ||
const K_STRING_MAX_LENGTH = (1 << 28) - 16; | ||
|
||
module.exports = { | ||
Buffer: SpecificBuffer(buffer.Buffer), | ||
SlowBuffer: buffer.SlowBuffer, | ||
INSPECT_MAX_BYTES: buffer.INSPECT_MAX_BYTES, | ||
kMaxLength: buffer.kMaxLength, | ||
kStringMaxLength: K_STRING_MAX_LENGTH, | ||
constants: { | ||
MAX_LENGTH: buffer.kMaxLength, | ||
MAX_STRING_LENGTH: K_STRING_MAX_LENGTH | ||
}, | ||
File: File, | ||
Blob: Blob | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
function SpecificBuffer (_Buffer) { | ||
const Buffer = function () { | ||
if (typeof arguments[0] === 'number') { | ||
return _Buffer.alloc(...arguments); | ||
} | ||
|
||
return _Buffer.from(...arguments); | ||
} | ||
|
||
Buffer.poolSize = _Buffer.poolSize; | ||
|
||
Object.defineProperty(Buffer, Symbol.hasInstance, { | ||
value: function (instance) { | ||
return instance instanceof _Buffer; | ||
} | ||
}); | ||
|
||
Buffer.isBuffer = function () { | ||
return _Buffer.isBuffer(...arguments); | ||
} | ||
|
||
Buffer.alloc = function () { | ||
return _Buffer.alloc(...arguments); | ||
} | ||
|
||
Buffer.allocUnsafe = function () { | ||
return _Buffer.allocUnsafe(...arguments); | ||
} | ||
|
||
Buffer.allocUnsafeSlow = function () { | ||
return _Buffer.allocUnsafeSlow(...arguments); | ||
} | ||
|
||
Buffer.from = function () { | ||
return _Buffer.from(...arguments); | ||
} | ||
|
||
Buffer.compare = function () { | ||
return _Buffer.compare(...arguments); | ||
} | ||
|
||
Buffer.isEncoding = function () { | ||
return _Buffer.isEncoding(...arguments); | ||
} | ||
|
||
Buffer.concat = function () { | ||
return _Buffer.concat(...arguments); | ||
} | ||
|
||
Buffer.byteLength = function () { | ||
return _Buffer.byteLength(...arguments); | ||
} | ||
|
||
Buffer.copyBytesFrom = function (offset, length) { | ||
|
||
} | ||
|
||
return Buffer; | ||
} | ||
|
||
module.exports = SpecificBuffer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const SpecificBuffer = require('./buffer'); | ||
const buffer = global.node.buffer; | ||
|
||
module.exports = { | ||
Buffer: SpecificBuffer(globalThis.Buffer), | ||
SlowBuffer: buffer.SlowBuffer, | ||
INSPECT_MAX_BYTES: buffer.INSPECT_MAX_BYTES, | ||
kMaxLength: buffer.kMaxLength, | ||
kStringMaxLength: buffer.kStringMaxLength, | ||
constants: buffer.constants, | ||
File: buffer.File, | ||
Blob: buffer.Blob, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters