-
Notifications
You must be signed in to change notification settings - Fork 20
Data Exporting #25
Data Exporting #25
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
.DS_Store | ||
tests/repo-tests* | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules | ||
|
||
test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
machine: | ||
node: | ||
version: stable | ||
|
||
dependencies: | ||
pre: | ||
- google-chrome --version | ||
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - | ||
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' | ||
- sudo apt-get update | ||
- sudo apt-get --only-upgrade install google-chrome-stable | ||
- google-chrome --version |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ const FixedSizeChunker = require('./chunker-fixed-size') | |
const through2 = require('through2') | ||
const UnixFS = require('ipfs-unixfs') | ||
const async = require('async') | ||
const events = require('events') | ||
const Readable = require('stream').Readable | ||
const pathj = require('path') | ||
|
||
exports = module.exports | ||
|
||
|
@@ -206,7 +209,6 @@ exports.import = (target, dagService, options, callback) => { | |
leafSize: raw.fileSize(), | ||
Name: '' | ||
}) | ||
|
||
cb() | ||
}) | ||
}, (cb) => { | ||
|
@@ -249,6 +251,114 @@ exports.import = (target, dagService, options, callback) => { | |
// function streamImporter (stream, callback) {} | ||
} | ||
|
||
exports.export = function () { | ||
// export into files by hash | ||
exports.export = function (hash, dagService, options, callback) { | ||
if (typeof options === 'function') { | ||
callback = options | ||
options = {} | ||
} | ||
|
||
const ee = new events.EventEmitter() | ||
dagService.get(hash, (err, fetchedNode) => { | ||
if (err) { | ||
if (callback) { | ||
return callback(err) | ||
} | ||
return | ||
} | ||
const data = UnixFS.unmarshal(fetchedNode.data) | ||
const type = data.type | ||
if (type === 'directory') { | ||
dirExporter(fetchedNode, hash, callback) | ||
} | ||
if (type === 'file') { | ||
fileExporter(fetchedNode, hash, false, callback) | ||
} | ||
}) | ||
return ee | ||
|
||
function fileExporter (node, name, dir, callback) { | ||
if (typeof dir === 'function') { callback = dir; dir = {} } | ||
var rs = new Readable() | ||
if (node.links.length === 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the existence of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as far as i can see we will always have an empty links array if there are no links |
||
const unmarshaledData = UnixFS.unmarshal(node.data) | ||
ee.emit('file', { stream: rs, path: name, dir: dir }) | ||
rs.push(unmarshaledData.data) | ||
rs.push(null) | ||
if (callback) { | ||
callback() | ||
} | ||
return | ||
} else { | ||
ee.emit('file', { stream: rs, path: name, dir: dir }) | ||
var init = false | ||
rs._read = () => { | ||
if (init) { | ||
return | ||
} | ||
init = true | ||
async.forEachSeries(node.links, (link, callback) => { | ||
dagService.get(link.hash, (err, res) => { | ||
if (err) { | ||
callback(err) | ||
} | ||
var unmarshaledData = UnixFS.unmarshal(res.data) | ||
rs.push(unmarshaledData.data) | ||
callback() | ||
}) | ||
}, (err) => { | ||
if (err) { | ||
if (callback) { | ||
return callback(err) | ||
} | ||
return | ||
} | ||
rs.push(null) | ||
if (callback) { | ||
callback() | ||
} | ||
return | ||
}) | ||
} | ||
} | ||
} | ||
|
||
function dirExporter (node, name, callback) { | ||
var rs = new Readable() | ||
if (node.links.length === 0) { | ||
rs.push(node.data) | ||
rs.push(null) | ||
ee.emit('file', {stream: rs, path: name}) | ||
if (callback) { | ||
callback() | ||
} | ||
return | ||
} else { | ||
async.forEachSeries(node.links, (link, callback) => { | ||
dagService.get(link.hash, (err, res) => { | ||
if (err) { | ||
callback(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing |
||
} | ||
var unmarshaledData = UnixFS.unmarshal(res.data) | ||
if (unmarshaledData.type === 'file') { | ||
return (fileExporter(res, pathj.join(name, link.name), callback)) | ||
} | ||
if (unmarshaledData.type === 'directory') { | ||
return (dirExporter(res, pathj.join(name, link.name), callback)) | ||
} | ||
callback() | ||
}) | ||
}, (err) => { | ||
if (err) { | ||
if (callback) { | ||
return callback(err) | ||
} | ||
return | ||
} | ||
if (callback) { | ||
callback() | ||
} | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
}) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
5 | ||
" $��G�,�A�4{���x�Z/.����D`�200Bytes.txt�/ | ||
" Y��9_)a���˹2�R�m�Ŗke�9��level-2 | ||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice if
fileExporter
anddirExporter
were in separate files and get the event emitter passed as an argument, that would make testing them independently also easier.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a bad idea! will work on that