Files: e257f2546f229a035921db80e8d18ba65b25c615 / modules / file-input.js
949 bytesRaw
1 | var u = require('../util') |
2 | var h = require('hyperscript') |
3 | var pull = require('pull-stream') |
4 | var mime = require('simple-mime')('application/octect-stream') |
5 | var split = require('split-buffer') |
6 | |
7 | var plugs = require('../plugs') |
8 | |
9 | var add = plugs.first(exports.sbot_blobs_add = []) |
10 | |
11 | exports.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