git ssb

0+

ev / microbay



forked from Dominic / patchbay

Tree: d5eb7683c93c7089b588c1e9b99aaa426b4da566

Files: d5eb7683c93c7089b588c1e9b99aaa426b4da566 / modules / file-input.js

949 bytesRaw
1var u = require('../util')
2var h = require('hyperscript')
3var pull = require('pull-stream')
4var mime = require('simple-mime')('application/octect-stream')
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(file.name)
27 })
28
29 })
30 )
31 }
32 reader.readAsArrayBuffer(file)
33 }
34 })
35}
36
37

Built with git-ssb-web