-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use allocUnsafe to allocate hash digests (#391)
* feat: use allocUnsafe to allocate hash digests * chore: remove dependencies * chore: remove dependencies * chore: update lockfile * chore: simplify comment
- Loading branch information
1 parent
1578883
commit 8ea1bb4
Showing
2 changed files
with
43 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null; | ||
|
||
/** | ||
* Where possible returns a Uint8Array of the requested size that references | ||
* uninitialized memory. Only use if you are certain you will immediately | ||
* overwrite every value in the returned `Uint8Array`. | ||
*/ | ||
export const allocUnsafe = isNode ? _allocUnsafeNode : _allocUnsafe; | ||
|
||
function _allocUnsafe(size = 0): Uint8Array { | ||
return new Uint8Array(size); | ||
} | ||
|
||
function _allocUnsafeNode(size = 0): Uint8Array { | ||
const out = Buffer.allocUnsafe(size); | ||
return new Uint8Array(out.buffer, out.byteOffset, out.byteLength); | ||
} |
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