summaryrefslogtreecommitdiff
path: root/std/node/buffer.ts
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2020-06-28 16:16:54 +0200
committerGitHub <noreply@github.com>2020-06-28 10:16:54 -0400
commitd779053dc6ea6aafef06f8a5e7f28cbbc8166864 (patch)
tree696572bfe0f1943819e6cd6632a86ad0f6f622c0 /std/node/buffer.ts
parent2da084058397efd6f517ba98c9882760ec0a7bd6 (diff)
feat(std/node): Add Buffer.allocUnsafe (#6533)
Diffstat (limited to 'std/node/buffer.ts')
-rw-r--r--std/node/buffer.ts9
1 files changed, 7 insertions, 2 deletions
diff --git a/std/node/buffer.ts b/std/node/buffer.ts
index e74ece196..b878092dc 100644
--- a/std/node/buffer.ts
+++ b/std/node/buffer.ts
@@ -60,8 +60,9 @@ export default class Buffer extends Uint8Array {
if (typeof fill === "string" && fill.length === 1 && encoding === "utf8")
buf.fill(fill.charCodeAt(0));
else bufFill = Buffer.from(fill, encoding);
- } else if (typeof fill === "number") buf.fill(fill);
- else if (fill instanceof Uint8Array) {
+ } else if (typeof fill === "number") {
+ buf.fill(fill);
+ } else if (fill instanceof Uint8Array) {
if (fill.length === 0) {
throw new TypeError(
`The argument "value" is invalid. Received ${fill.constructor.name} []`
@@ -89,6 +90,10 @@ export default class Buffer extends Uint8Array {
return buf;
}
+ static allocUnsafe(size: number): Buffer {
+ return new Buffer(size);
+ }
+
/**
* Returns the byte length of a string when encoded. This is not the same as
* String.prototype.length, which does not account for the encoding that is