git ssb

16+

Dominic / patchbay



Tree: c17210ec353dee6e28ecd08ebdc1c50a65d99dec

Files: c17210ec353dee6e28ecd08ebdc1c50a65d99dec / 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