Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCas <6506529+ThaUnknown@users.noreply.github.com>2022-11-11 03:21:03 +0300
committerGitHub <noreply@github.com>2022-11-11 03:21:03 +0300
commit1ba3e6c4530008c1c54cd44f3e95581ba4d89b00 (patch)
tree474214afea247f851b1d17d5b350940e98040174
parent46bddf7bf87b1c982f88851a0902b4992d368091 (diff)
parent8c3b6cbcc163b2cea2b7c6f12e6d6e4f19663d8a (diff)
Merge pull request #2394 from ThaUnknown/dead-code
fix: dead code
-rw-r--r--lib/file.js57
-rw-r--r--package.json1
2 files changed, 1 insertions, 57 deletions
diff --git a/lib/file.js b/lib/file.js
index f38fc0d..d25dca7 100644
--- a/lib/file.js
+++ b/lib/file.js
@@ -3,9 +3,7 @@ import { PassThrough } from 'streamx'
import { BlobWriteStream } from 'fast-blob-stream'
import streamToBuffer from 'stream-with-known-length-to-buffer'
import queueMicrotask from 'queue-microtask'
-import rangeParser from 'range-parser'
import mime from 'mime'
-import eos from 'end-of-stream'
import FileStream from './file-stream.js'
export default class File extends EventEmitter {
@@ -122,7 +120,7 @@ export default class File extends EventEmitter {
if (typeof window === 'undefined') throw new Error('browser-only method')
const writeStream = new BlobWriteStream(blob => {
cb(null, blob)
- }, { mimeType: this._getMimeType() })
+ }, { mimeType: mime.getType(this.name) || 'application/octet-stream' })
this.createReadStream().pipe(writeStream)
}
@@ -132,59 +130,6 @@ export default class File extends EventEmitter {
})
}
- _serve (req) {
- const res = {
- status: 200,
- headers: {
- // Support range-requests
- 'Accept-Ranges': 'bytes',
- 'Content-Type': mime.getType(this.name),
- 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
- Expires: '0'
- },
- body: req.method === 'HEAD' ? '' : 'STREAM'
- }
- // force the browser to download the file if if it's opened in a new tab
- if (req.destination === 'document') {
- res.headers['Content-Type'] = 'application/octet-stream'
- res.headers['Content-Disposition'] = 'attachment'
- res.body = 'DOWNLOAD'
- }
-
- // `rangeParser` returns an array of ranges, or an error code (number) if
- // there was an error parsing the range.
- let range = rangeParser(this.length, req.headers.range || '')
-
- if (range.constructor === Array) {
- res.status = 206 // indicates that range-request was understood
-
- // no support for multi-range request, just use the first range
- range = range[0]
-
- res.headers['Content-Range'] = `bytes ${range.start}-${range.end}/${this.length}`
- res.headers['Content-Length'] = `${range.end - range.start + 1}`
- } else {
- res.headers['Content-Length'] = this.length
- }
-
- const stream = req.method === 'GET' && this.createReadStream(range)
-
- let pipe = null
- if (stream) {
- this.emit('stream', { stream, req, file: this }, piped => {
- pipe = piped
-
- // piped stream might not close the original filestream on close/error, this is agressive but necessary
- eos(piped, () => {
- if (piped) piped.destroy()
- stream.destroy()
- })
- })
- }
-
- return [res, pipe || stream, pipe && stream]
- }
-
getStreamURL () {
if (!this._server) throw new Error('No server created')
const url = `${this._server.pathname}/${this._torrent.infoHash}/${encodeURI(this.path)}`
diff --git a/package.json b/package.json
index 57a7ed1..0035def 100644
--- a/package.json
+++ b/package.json
@@ -47,7 +47,6 @@
"cpus": "^1.0.3",
"create-torrent": "^5.0.6",
"debug": "^4.3.4",
- "end-of-stream": "^1.4.4",
"escape-html": "^1.0.3",
"fast-blob-stream": "^1.1.1",
"fs-chunk-store": "^3.0.1",