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

Response FileBlob.slice() return full file #616

Closed
gornostay25 opened this issue Jul 12, 2022 · 8 comments
Closed

Response FileBlob.slice() return full file #616

gornostay25 opened this issue Jul 12, 2022 · 8 comments
Labels
needs repro Needs an example to reproduce

Comments

@gornostay25
Copy link
Contributor

@Jarred-Sumner
if I return a slice, I will receive a full file

return new Response(Bun.file(data.abs).slice(opts.start, opts.end), {
            headers: data.headers,
            status: code
})

So I try to return an arrayBuffer

return new Promise((rs) => {
    Bun.file(data.abs).slice(opts.start, opts.end).arrayBuffer().then(arbf => {
        rs(
            new Response(arbf, {
                headers: data.headers,
                status: code
            })
        )
    })
})

It's work, but in docs slice return FileBlob (slice(begin?: number, end?: number): FileBlob;)
And Response constructor receive FileBlob **NOT arrayBuffer **

declare class Response implements BlobInterface {
  constructor(body: BlobPart | BlobPart[], options?: ResponseInit);

Originally posted by @gornostay25 in #589 (comment)

@Electroid
Copy link
Contributor

Hi @gornostay25, thanks for submitting this bug report. If you have time, do you mind providing an example that we can run to observe the issue? I tried to piece together what you provided but I don't think there's enough context.

@gornostay25
Copy link
Contributor Author

@Jarred-Sumner
Copy link
Collaborator

In the HTTP server (Bun.serve) right? If so, HTTP or HTTPS?

@gornostay25
Copy link
Contributor Author

gornostay25 commented Nov 5, 2022

@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented Nov 5, 2022

Is the workaround calling .arrayBuffer() or is that intentional? If it’s not intentional, could you try directly passing

new Response(Bun.file(data.abs).slice(opts.start, opts.end), { headers: data.headers, status: code })

@gornostay25
Copy link
Contributor Author

I don't know is it working now, but early it doesn't

@Lucifer1662
Copy link

Should these lines contain this.offset?
Otherwise sendfile/splice/copy_file_range will send from the begging of the src, which will ignore the .slice operation on the blob.
As both ReadFile and WriteFile classes use the offset, which would explain why .arrayBuffer() would work.

@gornostay25
Copy link
Contributor Author

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

No branches or pull requests

4 participants