Libraryless. Click here for Pure Java version (3186L/18K).
1 | static virtual NanoHTTPD.Response subBot_serveFileRange(File file, S mimeType, S rangeHeader) ctex { |
2 | S rangeValue = dropPrefix("bytes=", trim(rangeHeader)); |
3 | long fileLength = file.length(), start, end; |
4 | |
5 | if (rangeValue.startsWith("-")) { |
6 | end = fileLength-1; |
7 | start = fileLength-1-parseLong(dropPrefix("-", rangeValue)); |
8 | } else { |
9 | S[] range = rangeValue.split("-"); |
10 | start = parseLong(range[0]); |
11 | end = range.length > 1 ? min(fileLength-1, parseLong(range[1])) : fileLength-1; |
12 | } |
13 | |
14 | if (start <= end) { |
15 | long contentLength = end-start+1; |
16 | FileInputStream fileInputStream = new(file); |
17 | fileInputStream.skip(start); |
18 | virtual Response response = subBot_servePartialContent(mimeType, fileInputStream, contentLength); |
19 | call(response, "addHeader", "Content-Range", "bytes " + start + "-" + end + "/" + fileLength); |
20 | ret response; |
21 | } else |
22 | ret subBot_serveRangeNotSatisfiable(rangeHeader); |
23 | } |
Began life as a copy of #1014005
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1032345 |
Snippet name: | subBot_serveFileRange [dev.] |
Eternal ID of this version: | #1032345/9 |
Text MD5: | 468ceac486a1ce258a2e394ab703530c |
Transpilation MD5: | 31a95e903ad5e8148ae522d34b150ddb |
Author: | stefan |
Category: | javax / html |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-08-29 01:53:04 |
Source code size: | 955 bytes / 23 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 151 / 230 |
Version history: | 8 change(s) |
Referenced in: | [show references] |