git ssb

16+

Dominic / patchbay



Tree: 2a3b514162af82f82e2d8b229bcf5db9c72bbc96

Files: 2a3b514162af82f82e2d8b229bcf5db9c72bbc96 / modules / file-input.js

973 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 if (!file) return
17 var reader = new FileReader()
18 reader.onload = function () {
19 pull(
20 pull.values(split(new Buffer(reader.result), 64*1024)),
21 add(function (err, blob) {
22 if(err) return console.error(err)
23 onAdded({
24 link: blob,
25 name: file.name,
26 size: reader.result.length || reader.result.byteLength,
27 type: mime(file.name)
28 })
29
30 })
31 )
32 }
33 reader.readAsArrayBuffer(file)
34 }
35 })
36}
37
38

Built with git-ssb-web