main
js 93 lines 2.33 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 export type Destination = {
11 buffer: string,
12 done: boolean,
13 fatal: boolean,
14 error: mixed,
15 };
16
17 export opaque type PrecomputedChunk = string;
18 export opaque type Chunk = string;
19 export opaque type BinaryChunk = string;
20
21 export function scheduleMicrotask(callback: () => void) {
22 // TODO: Consider unifying this with the FB Flight stream config and
23 // adopting its microtask scheduling implementation.
24 callback();
25 }
26
27 export function scheduleWork(callback: () => void) {
28 // TODO: Consider unifying this with the FB Flight stream config and
29 // adopting its work scheduling implementation.
30 callback();
31 }
32
33 export function flushBuffered(destination: Destination) {}
34
35 export const supportsRequestStorage = false;
36 export const requestStorage: AsyncLocalStorage<Request | void> = null as any;
37
38 export function beginWriting(destination: Destination) {}
39
40 export function writeChunk(
41 destination: Destination,
42 chunk: Chunk | PrecomputedChunk | BinaryChunk,
43 ): void {
44 destination.buffer += chunk;
45 }
46
47 export function writeChunkAndReturn(
48 destination: Destination,
49 chunk: Chunk | PrecomputedChunk | BinaryChunk,
50 ): boolean {
51 destination.buffer += chunk;
52 return true;
53 }
54
55 export function completeWriting(destination: Destination) {}
56
57 export function close(destination: Destination) {
58 destination.done = true;
59 }
60
61 export function stringToChunk(content: string): Chunk {
62 return content;
63 }
64
65 export function stringToPrecomputedChunk(content: string): PrecomputedChunk {
66 return content;
67 }
68
69 export function typedArrayToBinaryChunk(
70 content: $ArrayBufferView,
71 ): BinaryChunk {
72 throw new Error('Not implemented.');
73 }
74
75 export const byteLengthOfChunk:
76 | null
77 | ((chunk: Chunk | PrecomputedChunk) => number) = null;
78
79 export function byteLengthOfBinaryChunk(chunk: BinaryChunk): number {
80 throw new Error('Not implemented.');
81 }
82
83 export function closeWithError(destination: Destination, error: mixed): void {
84 destination.done = true;
85 destination.fatal = true;
86 destination.error = error;
87 }
88
89 export {createFastHashJS as createFastHash} from './createFastHashJS';
90
91 export function readAsDataURL(blob: Blob): Promise<string> {
92 throw new Error('Not implemented.');
93 }