Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [Help needed] Implement Blob get data methods #4396

Closed
wants to merge 2 commits into from

Conversation

crowlKats
Copy link
Member

I am trying to implement Blob's stream, text & arrayBuffer methods, which allow the reading of data from a blob.
This would resolve #2303 & resolve #4142, and also allows me to finalize the tests for #4363.

The last thing missing is the implementation of the get stream algorithm, for which i need some help.

@@ -124,6 +126,36 @@ function processBlobParts(
return bytes;
}

function getStream(blobBytes: Uint8Array): ReadableStream {
return new ReadableStream({

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 ReadableStream({
  start(controller) {
      controller.enqueue(blobBytes);

Maybe?

I think these need some tests too. These would be great to have!

Copy link
Member Author

@crowlKats crowlKats Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ye added a test for the text() method. i was considering other tests as well, but text() relies on code that appears in the arrayBuffer() method, and that again uses code from the stream() method, so if any of them fail, the test would fail as well + testing those 2 would be a bit of a pain and stupid, as testing arrayBuffer() would literally be the same code as text()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hayd's suggestion is correct. ReadableStream must be constructed with data sources. In this case, actually data is not stream but just fixed byte array. So it's enough to pass entire bytes to controller (ReadableStreamController). It may be good to slice bytes into chunks if data is too big. But blob is immutable data. controller.enqueue(blobBytes); is enough.

See: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream

@@ -124,6 +126,36 @@ function processBlobParts(
return bytes;
}

function getStream(blobBytes: Uint8Array): ReadableStream {
return new ReadableStream({

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hayd's suggestion is correct. ReadableStream must be constructed with data sources. In this case, actually data is not stream but just fixed byte array. So it's enough to pass entire bytes to controller (ReadableStreamController). It may be good to slice bytes into chunks if data is too big. But blob is immutable data. controller.enqueue(blobBytes); is enough.

See: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream

@@ -124,6 +126,36 @@ function processBlobParts(
return bytes;
}

function getStream(blobBytes: Uint8Array): ReadableStream {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function getStream(blobBytes: Uint8Array): ReadableStream {
function getStream(blobBytes: Uint8Array): domTypes.ReadableStream<Uint8Array> {

You'll get type error because srandarized's stream is incompatible with deno's global type definition, but I think this is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reading Blobs and new blob reading methods
3 participants