1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
use js_sys::{Array, ArrayBuffer, Error, Promise, Uint8Array};
use wasm_bindgen::prelude::*;
use web_sys::AbortSignal;
pub use ReadableStreamDefaultReadResult as ReadableStreamReadResult;
use crate::queuing_strategy::QueuingStrategy;
use crate::writable::sys::WritableStream;
use super::into_underlying_byte_source::IntoUnderlyingByteSource;
use super::into_underlying_source::IntoUnderlyingSource;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_name = ReadableStream, typescript_type = "ReadableStream")]
#[derive(Clone, Debug)]
pub type ReadableStream;
#[wasm_bindgen(constructor)]
pub fn new() -> ReadableStream;
#[wasm_bindgen(constructor)]
pub(crate) fn new_with_source(
source: IntoUnderlyingSource,
strategy: QueuingStrategy,
) -> ReadableStream;
#[wasm_bindgen(constructor, catch)]
pub(crate) fn new_with_byte_source(
source: IntoUnderlyingByteSource,
) -> Result<ReadableStream, Error>;
#[wasm_bindgen(method, getter, js_name = locked)]
pub fn is_locked(this: &ReadableStream) -> bool;
#[wasm_bindgen(method, js_name = cancel)]
pub fn cancel(this: &ReadableStream) -> Promise;
#[wasm_bindgen(method, js_name = cancel)]
pub fn cancel_with_reason(this: &ReadableStream, reason: &JsValue) -> Promise;
#[wasm_bindgen(method, catch, js_name = getReader)]
pub fn get_reader(this: &ReadableStream) -> Result<ReadableStreamDefaultReader, Error>;
#[wasm_bindgen(method, catch, js_name = getReader)]
pub fn get_reader_with_options(
this: &ReadableStream,
opts: ReadableStreamGetReaderOptions,
) -> Result<ReadableStreamBYOBReader, Error>;
#[wasm_bindgen(method, js_name = pipeTo)]
pub fn pipe_to(this: &ReadableStream, dest: &WritableStream, opts: PipeOptions) -> Promise;
#[wasm_bindgen(method, catch, js_name = tee)]
pub fn tee(this: &ReadableStream) -> Result<Array, Error>;
}
#[wasm_bindgen]
extern "C" {
#[derive(Clone, Debug)]
pub type ReadableStreamDefaultController;
#[wasm_bindgen(method, getter, js_name = desiredSize)]
pub fn desired_size(this: &ReadableStreamDefaultController) -> Option<f64>;
#[wasm_bindgen(method, js_name = close)]
pub fn close(this: &ReadableStreamDefaultController);
#[wasm_bindgen(method, js_name = enqueue)]
pub fn enqueue(this: &ReadableStreamDefaultController, chunk: &JsValue);
#[wasm_bindgen(method, js_name = error)]
pub fn error(this: &ReadableStreamDefaultController, error: &JsValue);
}
#[wasm_bindgen]
extern "C" {
#[derive(Clone, Debug)]
pub type ReadableByteStreamController;
#[wasm_bindgen(method, getter, js_name = byobRequest)]
pub fn byob_request(this: &ReadableByteStreamController) -> Option<ReadableStreamBYOBRequest>;
#[wasm_bindgen(method, getter, js_name = desiredSize)]
pub fn desired_size(this: &ReadableByteStreamController) -> Option<f64>;
#[wasm_bindgen(method, js_name = close)]
pub fn close(this: &ReadableByteStreamController);
#[wasm_bindgen(method, js_name = enqueue)]
pub fn enqueue(this: &ReadableByteStreamController, chunk: &ArrayBufferView);
#[wasm_bindgen(method, js_name = error)]
pub fn error(this: &ReadableByteStreamController, error: &JsValue);
}
#[wasm_bindgen]
extern "C" {
#[derive(Clone, Debug)]
pub type ReadableStreamBYOBRequest;
#[wasm_bindgen(method, getter, js_name = view)]
pub fn view(this: &ReadableStreamBYOBRequest) -> Option<ArrayBufferView>;
#[wasm_bindgen(method, js_name = respond)]
pub fn respond(this: &ReadableStreamBYOBRequest, bytes_written: u32);
#[wasm_bindgen(method, js_name = respondWithNewView)]
pub fn respond_with_new_view(this: &ReadableStreamBYOBRequest, view: &ArrayBufferView);
}
#[wasm_bindgen]
extern "C" {
#[derive(Clone, Debug)]
pub type ArrayBufferView;
#[wasm_bindgen(method, getter, js_name = buffer)]
pub fn buffer(this: &ArrayBufferView) -> ArrayBuffer;
#[wasm_bindgen(method, getter, js_name = byteOffset)]
pub fn byte_offset(this: &ArrayBufferView) -> u32;
#[wasm_bindgen(method, getter, js_name = byteLength)]
pub fn byte_length(this: &ArrayBufferView) -> u32;
}
#[wasm_bindgen]
extern "C" {
#[derive(Clone, Debug)]
pub type ReadableStreamGenericReader;
#[wasm_bindgen(method, getter, js_name = closed)]
pub fn closed(this: &ReadableStreamGenericReader) -> Promise;
#[wasm_bindgen(method, js_name = cancel)]
pub fn cancel(this: &ReadableStreamGenericReader) -> Promise;
#[wasm_bindgen(method, js_name = cancel)]
pub fn cancel_with_reason(this: &ReadableStreamGenericReader, reason: &JsValue) -> Promise;
#[wasm_bindgen(method, catch, js_name = releaseLock)]
pub fn release_lock(this: &ReadableStreamGenericReader) -> Result<(), Error>;
}
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = ReadableStreamGenericReader)]
#[derive(Clone, Debug)]
pub type ReadableStreamDefaultReader;
#[wasm_bindgen(method, js_name = read)]
pub fn read(this: &ReadableStreamDefaultReader) -> Promise;
}
#[wasm_bindgen]
extern "C" {
#[derive(Clone, Debug)]
pub type ReadableStreamDefaultReadResult;
#[wasm_bindgen(method, getter, js_name = done)]
pub fn is_done(this: &ReadableStreamDefaultReadResult) -> bool;
#[wasm_bindgen(method, getter, js_name = value)]
pub fn value(this: &ReadableStreamDefaultReadResult) -> JsValue;
}
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = ReadableStreamGenericReader)]
#[derive(Clone, Debug)]
pub type ReadableStreamBYOBReader;
#[wasm_bindgen(method, js_name = read)]
pub fn read(this: &ReadableStreamBYOBReader, view: &ArrayBufferView) -> Promise;
}
#[wasm_bindgen]
extern "C" {
#[derive(Clone, Debug)]
pub type ReadableStreamBYOBReadResult;
#[wasm_bindgen(method, getter, js_name = done)]
pub fn is_done(this: &ReadableStreamBYOBReadResult) -> bool;
#[wasm_bindgen(method, getter, js_name = value)]
pub fn value(this: &ReadableStreamBYOBReadResult) -> Option<Uint8Array>;
}
#[wasm_bindgen]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ReadableStreamReaderMode {
BYOB = "byob",
}
#[wasm_bindgen]
#[derive(Clone, Debug)]
pub struct ReadableStreamGetReaderOptions {
mode: ReadableStreamReaderMode,
}
impl ReadableStreamGetReaderOptions {
pub fn new(mode: ReadableStreamReaderMode) -> Self {
Self { mode }
}
}
#[wasm_bindgen]
impl ReadableStreamGetReaderOptions {
#[wasm_bindgen(getter, js_name = mode)]
pub fn mode(&self) -> ReadableStreamReaderMode {
self.mode
}
}
#[wasm_bindgen]
#[derive(Clone, Debug, Default)]
pub struct PipeOptions {
prevent_close: bool,
prevent_cancel: bool,
prevent_abort: bool,
signal: Option<AbortSignal>,
}
impl PipeOptions {
pub fn new(
prevent_close: bool,
prevent_cancel: bool,
prevent_abort: bool,
signal: Option<AbortSignal>,
) -> Self {
Self {
prevent_close,
prevent_cancel,
prevent_abort,
signal,
}
}
}
#[wasm_bindgen]
impl PipeOptions {
#[wasm_bindgen(getter, js_name = preventClose)]
pub fn prevent_close(&self) -> bool {
self.prevent_close
}
#[wasm_bindgen(getter, js_name = preventCancel)]
pub fn prevent_cancel(&self) -> bool {
self.prevent_cancel
}
#[wasm_bindgen(getter, js_name = preventAbort)]
pub fn prevent_abort(&self) -> bool {
self.prevent_abort
}
#[wasm_bindgen(getter, js_name = signal)]
pub fn signal(&self) -> Option<AbortSignal> {
self.signal.clone()
}
}