diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2015-07-08 04:54:47 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2015-07-08 04:54:47 +0300 |
commit | d7ed2c70c392fe3210dca8d11686c9f0ec0dfc80 (patch) | |
tree | 1eed507cf974e3639a94231d172a2f25a45799df /lib/file-stream.js | |
parent | eec68d091afcf77e7d219fd78d5dccc95f91d85c (diff) |
BREAKING: Add file.appendTo(); remove file.pipe(videoNode)
# Removed API `file.createReadStream().pipe(videoNode)`
Previously, the `stream.pipe` method was overridden in a non-standard
and confusing way to be able to pipe to `<video>` and `<audio>` tags.
This is removed now. `stream.pipe` still exists, but it works just like
in node now.
# New API: `file.appendTo(rootElem, function callback (err, elem) {})`
Show the file in a the browser by appending it to the DOM. This is a
powerful function
that handles many file types like video (.mp4, .webm, .m4v, etc.),
audio (.m4a, .mp3,
.wav, etc.), images (.jpg, .gif, .png, etc.), and other file formats
(.pdf, .md, .txt,
etc.).
The file will be fetched from the network with highest priority and
streamed into the
page (if it's video or audio). In some cases, video or audio files will
not be streamable
because they're not in a format that the browser can stream so the file
will be fully downloaded before being played. For other non-streamable
file types like images and PDFs,
the file will be downloaded then displayed.
`rootElem` is a container element (CSS selector or reference to DOM
node) that the content
will be shown in. A new DOM node will be created for the content and
appended to
`rootElem`.
`callback` will be called once the file is visible to the user.
`callback` must be
specified, and will be called with a an `Error` (or `null`) and the new
DOM node that is
displaying the content.
```js
file.appendTo('#containerElement', function (err, elem) {
if (err) throw err // file failed to download or display in the DOM
console.log('New DOM node with the content', elem)
})
```
Fixes #370
Diffstat (limited to 'lib/file-stream.js')
-rw-r--r-- | lib/file-stream.js | 20 |
1 files changed, 0 insertions, 20 deletions
diff --git a/lib/file-stream.js b/lib/file-stream.js index 365b8da..05ae3eb 100644 --- a/lib/file-stream.js +++ b/lib/file-stream.js @@ -35,7 +35,6 @@ function FileStream (file, opts) { self.startPiece = offset / pieceLength | 0 self.endPiece = (opts.end + file.offset) / pieceLength | 0 - self._extname = path.extname(file.name).toLowerCase() self._storage = file.storage self._piece = self.startPiece self._missing = self.length @@ -95,25 +94,6 @@ FileStream.prototype.notify = function () { }) } -FileStream.prototype.pipe = function (dst) { - var self = this - var pipe = stream.Readable.prototype.pipe - - // <video> or <audio> tag - if (dst && (dst.nodeName === 'VIDEO' || dst.nodeName === 'AUDIO')) { - var type = { - '.m4a': 'audio/mp4; codecs="mp4a.40.5"', - '.m4v': 'video/mp4; codecs="avc1.640029, mp4a.40.5"', - '.mp3': 'audio/mpeg', - '.mp4': 'video/mp4; codecs="avc1.640029, mp4a.40.5"', - '.webm': 'video/webm; codecs="vorbis, vp8"' - }[self._extname] - return pipe.call(self, new MediaStream(dst, { type: type })) - } else { - return pipe.call(self, dst) - } -} - FileStream.prototype.destroy = function () { var self = this if (self.destroyed) return |