git ssb

0+

ev / microbay



forked from Dominic / patchbay

Tree: 0b5a32431a545be14a4887d48c7ce5b1eddca8d7

Files: 0b5a32431a545be14a4887d48c7ce5b1eddca8d7 / modules / file-input.js

935 bytesRaw
1var u = require('../util')
2var h = require('hyperscript')
3var pull = require('pull-stream')
4var mime = require('mime-types')
5var split = require('split-buffer')
6
7var plugs = require('../plugs')
8
9var add = plugs.first(exports.sbot_blobs_add = [])
10
11exports.file_input = function FileInput(onAdded) {
12
13 return h('input', { type: 'file',
14 onchange: function (ev) {
15 var file = ev.target.files[0]
16 var reader = new FileReader()
17 reader.onload = function () {
18 pull(
19 pull.values(split(new Buffer(reader.result), 64*1024)),
20 add(function (err, blob) {
21 if(err) return console.error(err)
22 onAdded({
23 link: blob,
24 name: file.name,
25 size: reader.result.length || reader.result.byteLength,
26 type: mime.contentType(file.name)
27 })
28
29 })
30 )
31 }
32 reader.readAsArrayBuffer(file)
33 }
34 })
35}
36
37
38
39
40
41

Built with git-ssb-web