git ssb

16+

Dominic / patchbay



Tree: b7930733e8dd27caf4551cd4282b20aff09b20dd

Files: b7930733e8dd27caf4551cd4282b20aff09b20dd / modules_core / file-input.js

1095 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
7module.exports = {
8 needs: {sbot_blobs_add: 'first'},
9 gives: 'file_input',
10 create: function (api) {
11 return function FileInput(onAdded) {
12 return h('input', { type: 'file',
13 onchange: function (ev) {
14 var file = ev.target.files[0]
15 if (!file) return
16 var reader = new FileReader()
17 reader.onload = function () {
18 pull(
19 pull.values(split(new Buffer(reader.result), 64*1024)),
20 api.sbot_blobs_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}
38
39

Built with git-ssb-web