send icon indicating copy to clipboard operation
send copied to clipboard

Byte-Range Support?

Open jcready opened this issue 7 years ago • 10 comments

Are there plans to add byte-range support to this? Similar to the send module that express uses?

jcready avatar Jun 10 '17 15:06 jcready

@jcready try https://github.com/koajs/koa-range :)

haoxins avatar Jun 11 '17 07:06 haoxins

Ahh, thanks @coderhaoxin. However doesn't this mean that if a client sent a request for a very large file (let's say 1GB) with a Range: 0-1 header that, while the client would correctly only get the first 2 bytes, the server would continue reading from disk and emitting 'data' events until the entire 1GB file had been read? And the file descriptor would remain open long after the request/response transaction had been completed?

jcready avatar Jun 11 '17 14:06 jcready

Similarly, if a client sent a request with Range: -1 the read stream created by this module would have to read the entire file before finally being able to send the last byte.

jcready avatar Jun 11 '17 17:06 jcready

  1. I don't serve files directly on my node.js server (in production). They are served via CDN :) 😢
  2. But just as you said, I think it's reasonable to add range support in koa-send, just as pillarjs/send
  3. I'm also thinking about the possibility to dep pillarjs/send :)

haoxins avatar Jun 12 '17 06:06 haoxins

Anyone working on this? I am currently using koa-send and need byte-range support. I'd be willing to contribute to this since I'll need to write it anyway.

PFWhite avatar Apr 17 '18 02:04 PFWhite

@PFWhite PR welcome :)

haoxins avatar Apr 18 '18 06:04 haoxins

@coderhaoxin PR up!

PFWhite avatar Apr 19 '18 02:04 PFWhite

Why not simply depend on pillarjs/send?

jcready avatar Apr 19 '18 02:04 jcready

I'm not familiar with the library. I instead read the spec, wrote the tests and implemented the feature.

Also I recently wasted 8 hours tracking down an issue with a body parsing Middleware that didn't couldn't read multipart form data without a content length so I had to write one with busboy.

Here I knew what I needed, how to do it, how long it would take, didn't want another dependency, and saw that people wanted this too so why not write it and give back to Koa-send.

PFWhite avatar Apr 19 '18 03:04 PFWhite

https://github.com/koajs/send/pull/121 i see there was a pr here that hasn't fixed its merge conflicts, i could really use this for my own application

Meleeman01 avatar Dec 09 '21 17:12 Meleeman01