UNPKG

3.79 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 /**
82 * Decodes a string of Base64-encoded data into bytes, and encodes those bytes into a string using Latin-1 (ISO-8859-1).
83 *
84 * This function is only provided for compatibility with legacy web platform APIs
85 * and should never be used in new code, because they use strings to represent
86 * binary data and predate the introduction of typed arrays in JavaScript.
87 * For code running using Node.js APIs, converting between base64-encoded strings
88 * and binary data should be performed using `Buffer.from(str, 'base64')` and
89 * `buf.toString('base64')`.
90 *
91 * @deprecated dom compatibility
92 */
93 export function atob(input: string): string;
94
95 /**
96 * Decodes a string into bytes using Latin-1 (ISO-8859), and encodes those bytes into a string using Base64.
97 *
98 * This function is only provided for compatibility with legacy web platform APIs
99 * and should never be used in new code, because they use strings to represent
100 * binary data and predate the introduction of typed arrays in JavaScript.
101 * For code running using Node.js APIs, converting between base64-encoded strings
102 * and binary data should be performed using `Buffer.from(str, 'base64')` and
103 * `buf.toString('base64')`.
104 *
105 * @deprecated dom compatibility
106 */
107 export function btoa(input: string): string;
108}
109
110declare module 'node:buffer' {
111 export * from 'buffer';
112}