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:
Diffstat (limited to 'lib/file.js')
-rw-r--r--lib/file.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/file.js b/lib/file.js
index ff19a1c..5f8021c 100644
--- a/lib/file.js
+++ b/lib/file.js
@@ -7,6 +7,7 @@ var inherits = require('inherits')
var path = require('path')
var render = require('render-media')
var stream = require('readable-stream')
+var streamToBlob = require('stream-to-blob')
var streamToBlobURL = require('stream-to-blob-url')
var streamToBuffer = require('stream-with-known-length-to-buffer')
@@ -74,10 +75,14 @@ File.prototype.getBuffer = function (cb) {
streamToBuffer(this.createReadStream(), this.length, cb)
}
+File.prototype.getBlob = function (cb) {
+ if (typeof window === 'undefined') throw new Error('browser-only method')
+ streamToBlob(this.createReadStream(), this._getMimeType(), cb)
+}
+
File.prototype.getBlobURL = function (cb) {
if (typeof window === 'undefined') throw new Error('browser-only method')
- var mime = render.mime[path.extname(this.name).toLowerCase()]
- streamToBlobURL(this.createReadStream(), mime, cb)
+ streamToBlobURL(this.createReadStream(), this._getMimeType(), cb)
}
File.prototype.appendTo = function (elem, cb) {
@@ -90,6 +95,10 @@ File.prototype.renderTo = function (elem, cb) {
render.render(this, elem, cb)
}
+File.prototype._getMimeType = function () {
+ return render.mime[path.extname(this.name).toLowerCase()]
+}
+
File.prototype._destroy = function () {
this._destroyed = true
this._torrent = null