git ssb

16+

Dominic / patchbay



Tree: ba7439117c4a64cf7928c63d64fd58acd9898993

Files: ba7439117c4a64cf7928c63d64fd58acd9898993 / modules_core / file-input.js

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

Built with git-ssb-web