mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
buffer: add buffer.isUtf8 for utf8 validation
PR-URL: https://github.com/nodejs/node/pull/45947 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
07fdbbd015
commit
d5a08c7e11
7 changed files with 131 additions and 1 deletions
|
@ -57,6 +57,7 @@ const {
|
|||
compareOffset,
|
||||
createFromString,
|
||||
fill: bindingFill,
|
||||
isUtf8: bindingIsUtf8,
|
||||
indexOfBuffer,
|
||||
indexOfNumber,
|
||||
indexOfString,
|
||||
|
@ -84,7 +85,8 @@ const {
|
|||
const {
|
||||
isAnyArrayBuffer,
|
||||
isArrayBufferView,
|
||||
isUint8Array
|
||||
isUint8Array,
|
||||
isTypedArray,
|
||||
} = require('internal/util/types');
|
||||
const {
|
||||
inspect: utilInspect
|
||||
|
@ -1314,10 +1316,19 @@ function atob(input) {
|
|||
return Buffer.from(input, 'base64').toString('latin1');
|
||||
}
|
||||
|
||||
function isUtf8(input) {
|
||||
if (isTypedArray(input) || isAnyArrayBuffer(input)) {
|
||||
return bindingIsUtf8(input);
|
||||
}
|
||||
|
||||
throw new ERR_INVALID_ARG_TYPE('input', ['TypedArray', 'Buffer'], input);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Buffer,
|
||||
SlowBuffer,
|
||||
transcode,
|
||||
isUtf8,
|
||||
|
||||
// Legacy
|
||||
kMaxLength,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue