Possible to get 'total bytes sent' and 'stream end' from ctx.seekableStream ?
See original GitHub issueI’m using ctx.seekableStream(file.inputStream(), "audio/mpeg")
to stream files to the client and I’m planning to log some statistics about how many bytes have actually been sent. As far as I understand the browser it will call the endpoint multiple times to get a small chunk on every request.
Is it possible to get this information from the seekable stream somehow?
And is it possible to identify when the stream (chunk) ended?
Ty for any information.
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Possible to get 'total bytes sent' and 'stream end' from ctx. ...
I'm using ctx.seekableStream(file.inputStream(), "audio/mpeg") to stream files to the client and I'm planning to log some statistics about how many bytes ...
Read more >How to get total bytes transferred by stream?
I need to collect statistics of usage and total bytes send and received by server. I suppose, in MediaEventListener.onStop() should be some ...
Read more >Java Advanced Imaging: Class SeekableStream
An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of...
Read more >Archive - v3 documentation
seekableStream (resultStream) // set a stream that will be sent to the client in byte ranges ctx.contentType(contentType) // set the response content type ......
Read more >How to correctly calculate the the number of bytes ...
Alright, I made something that essentially is a passthrough, but calls a callback with data as it comes in: // creates a stream...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Nice ! I’ll add an “info” tag to the issue 😃
I think I solved the “mystery” 🙂.
CountingInputStream
counts the skipped bytes as well meaning each request that reads only a chunk of the file is counted as “read bytes” + “skipped bytes” to find position. In the case where the whole file was read at once I was simply counting the bytes too early since the stream is read afterctx.result(inputStream)
returned.So I ended up writing a new
CountingInputStream
implementation instead of a newSeekableWriter
like this:And I’m using it like this: