Add Blob.stream() method (#2140)

This enables a ReadableStream to be obtained for a file, which can then
be handled with e.g. https://github.com/MattiasBuelens/wasm-streams

    let file: web_sys::File = ...;
    let stream = wasm_streams::readable::ReadableStream::from(
        file.stream()
            .unchecked_into::<wasm_streams::readable::sys::ReadableStream>(),
    );

WebIDL source: https://w3c.github.io/FileAPI/#blob-section
Docs: https://developer.mozilla.org/en-US/docs/Web/API/Blob/stream
This commit is contained in:
str4d 2020-05-18 23:59:16 +12:00 committed by GitHub
parent adad1fbf41
commit 6ba8c6c2ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -212,6 +212,14 @@ extern "C" {
end: f64,
content_type: &str,
) -> Result<Blob, JsValue>;
#[cfg(feature = "ReadableStream")]
# [ wasm_bindgen ( method , structural , js_class = "Blob" , js_name = stream ) ]
#[doc = "The `stream()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Blob/stream)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Blob`, `ReadableStream`*"]
pub fn stream(this: &Blob) -> ReadableStream;
# [ wasm_bindgen ( method , structural , js_class = "Blob" , js_name = text ) ]
#[doc = "The `text()` method."]
#[doc = ""]

View File

@ -29,6 +29,8 @@ interface Blob {
[Clamp] optional long long end,
optional DOMString contentType);
// read from the Blob.
[NewObject] ReadableStream stream();
[NewObject] Promise<DOMString> text();
[NewObject] Promise<ArrayBuffer> arrayBuffer();
};