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 /README.md | |
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 'README.md')
-rw-r--r-- | README.md | 37 |
1 files changed, 30 insertions, 7 deletions
@@ -174,13 +174,9 @@ client.add(magnetUri, function (torrent) { // Let's say the first file is a webm (vp8) or mp4 (h264) video... var file = torrent.files[0] - // Create a video element - var video = document.createElement('video') - video.controls = true - document.body.appendChild(video) - - // Stream the video into the video tag - file.createReadStream().pipe(video) + // Stream the video! + // Specify a container element (CSS selector or reference to DOM node) + file.appendTo('body') }) ``` @@ -503,6 +499,33 @@ file.getBuffer(function (err, buffer) { }) ``` +#### `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) +}) +``` + #### `file.getBlobURL(function callback (err, url) {})` Get a url which can be used in the browser to refer to the file. |