Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
add createAddStream feature
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Jun 6, 2016
1 parent dd344e4 commit ea0eb40
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"form-data": "^1.0.0-rc3",
"gulp": "^3.9.1",
"idb-plus-blob-store": "^1.1.2",
"interface-ipfs-core": "^0.2.0",
"interface-ipfs-core": "^0.2.2",
"left-pad": "^1.1.0",
"lodash": "^4.11.2",
"mocha": "^2.5.1",
Expand All @@ -67,7 +67,7 @@
"glob": "^7.0.3",
"hapi": "^13.4.1",
"ipfs-bitswap": "^0.4.1",
"ipfs-api": "^5.0.0",
"ipfs-api": "^5.0.1",
"ipfs-block": "^0.3.0",
"ipfs-block-service": "^0.4.0",
"ipfs-merkle-dag": "^0.6.0",
Expand Down
49 changes: 42 additions & 7 deletions src/core/ipfs/files.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,57 @@
'use strict'

const Importer = require('ipfs-unixfs-engine').importer
const Exporter = require('ipfs-unixfs-engine').exporter
const unixfsEngine = require('ipfs-unixfs-engine')
const Importer = unixfsEngine.Importer
const Exporter = unixfsEngine.Exporter
const UnixFS = require('ipfs-unixfs')
const bs58 = require('bs58')
const through = require('through2')
const isStream = require('isstream')
const promisify = require('promisify-es6')
const Duplex = require('stream').Duplex

module.exports = function files (self) {
return {
createAddStream: promisify((callback) => {
// TODO: wip
if (data === undefined) {
return new Importer(self._dagS)
createAddStream: (callback) => {
const i = new Importer(self._dagS)
const ds = new Duplex({ objectMode: true })

ds._read = (n) => {}
ds._write = (file, enc, next) => {
i.write(file)
next()
}
}),

ds.end = () => {
i.end()
}

let counter = 0

i.on('data', (file) => {
counter++
self.object.get(file.multihash, (err, node) => {
if (err) {
return ds.emit('error', err)
}
ds.push({path: file.path, node: node})
counter--
})
})

i.on('end', () => {
function canFinish () {
if (counter === 0) {
ds.push(null)
} else {
setTimeout(canFinish, 100)
}
}
canFinish()
})

callback(null, ds)
},
add: promisify((data, callback) => {
// Buffer input
if (Buffer.isBuffer(data)) {
Expand Down

0 comments on commit ea0eb40

Please sign in to comment.