UNPKG

2.42 kBTypeScriptView Raw
1declare module 'buffer' {
2 import { BinaryLike } from 'crypto';
3
4 export const INSPECT_MAX_BYTES: number;
5 export const kMaxLength: number;
6 export const kStringMaxLength: number;
7 export const constants: {
8 MAX_LENGTH: number;
9 MAX_STRING_LENGTH: number;
10 };
11 const BuffType: typeof Buffer;
12
13 export type TranscodeEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "latin1" | "binary";
14
15 export function transcode(source: Uint8Array, fromEnc: TranscodeEncoding, toEnc: TranscodeEncoding): Buffer;
16
17 export const SlowBuffer: {
18 /** @deprecated since v6.0.0, use `Buffer.allocUnsafeSlow()` */
19 new(size: number): Buffer;
20 prototype: Buffer;
21 };
22
23 export { BuffType as Buffer };
24
25 /**
26 * @experimental
27 */
28 export interface BlobOptions {
29 /**
30 * @default 'utf8'
31 */
32 encoding?: BufferEncoding;
33
34 /**
35 * The Blob content-type. The intent is for `type` to convey
36 * the MIME media type of the data, however no validation of the type format
37 * is performed.
38 */
39 type?: string;
40 }
41
42 /**
43 * @experimental
44 */
45 export class Blob {
46 /**
47 * Returns a promise that fulfills with an {ArrayBuffer} containing a copy of the `Blob` data.
48 */
49 readonly size: number;
50
51 /**
52 * The content-type of the `Blob`.
53 */
54 readonly type: string;
55
56 /**
57 * Creates a new `Blob` object containing a concatenation of the given sources.
58 *
59 * {ArrayBuffer}, {TypedArray}, {DataView}, and {Buffer} sources are copied into
60 * the 'Blob' and can therefore be safely modified after the 'Blob' is created.
61 *
62 * String sources are also copied into the `Blob`.
63 */
64 constructor(sources: Array<(BinaryLike | Blob)>, options?: BlobOptions);
65
66 arrayBuffer(): Promise<ArrayBuffer>;
67
68 /**
69 * @param start The starting index.
70 * @param end The ending index.
71 * @param type The content-type for the new `Blob`
72 */
73 slice(start?: number, end?: number, type?: string): Blob;
74
75 /**
76 * Returns a promise that resolves the contents of the `Blob` decoded as a UTF-8 string.
77 */
78 text(): Promise<string>;
79 }
80}
81
82declare module 'node:buffer' {
83 export * from 'buffer';
84}