Skip to content

Commit

Permalink
feat(node:buffer): allow overriding Buffer with globalThis
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 8, 2023
1 parent 9141c15 commit 1337f98
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/runtime/node/buffer/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// https://nodejs.org/api/buffer.html
import type buffer from "node:buffer";
import { notImplemented } from "../../_internal/utils";
import { Buffer, kMaxLength, INSPECT_MAX_BYTES, SlowBuffer } from "./_buffer";
import {
Buffer as _Buffer,
kMaxLength,
INSPECT_MAX_BYTES,
SlowBuffer,
} from "./_buffer";
import { File } from "./_file";

// @ts-ignore
export { Buffer, kMaxLength, INSPECT_MAX_BYTES, SlowBuffer } from "./_buffer";
export { kMaxLength, INSPECT_MAX_BYTES, SlowBuffer } from "./_buffer";

export const Buffer = globalThis.Buffer || _Buffer;

export { File } from "./_file";

// @ts-expect-eerror https://github.com/unjs/unenv/issues/64
Expand All @@ -25,7 +32,7 @@ export const constants = {
};

export default <typeof buffer>{
Buffer: Buffer as any as typeof buffer.Buffer,
Buffer,
SlowBuffer: SlowBuffer as any as typeof buffer.SlowBuffer,
kMaxLength,
INSPECT_MAX_BYTES,
Expand Down

0 comments on commit 1337f98

Please sign in to comment.