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:
authorThaUnknown <6506529+ThaUnknown@users.noreply.github.com>2022-11-11 02:30:48 +0300
committerThaUnknown <6506529+ThaUnknown@users.noreply.github.com>2022-11-11 02:30:48 +0300
commit2839c7a55222d5b74feb2ce423b3cc2be61ee4e8 (patch)
treee7c31635d0fc1d0f0f9f821556e9b768af7d0aba
parent6d7875cc045601395fcc1213c5372f5bfeaa8067 (diff)
fix: remove 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 e972113..1199fb8 100644
--- a/lib/file.js
+++ b/lib/file.js
@@ -3,9 +3,7 @@ const { PassThrough } = require('streamx')
const { BlobWriteStream } = require('fast-blob-stream')
const streamToBuffer = require('stream-with-known-length-to-buffer')
const queueMicrotask = require('queue-microtask')
-const rangeParser = require('range-parser')
const mime = require('mime')
-const eos = require('end-of-stream')
const FileStream = require('./file-stream.js')
class File extends EventEmitter {
@@ -122,7 +120,7 @@ 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 @@ 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 f90297d..19aebb4 100644
--- a/package.json
+++ b/package.json
@@ -46,7 +46,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",