Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.

fix: make exporter report file sizes without protobuf overhead #20

Merged
merged 2 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/dir-flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const cat = require('pull-cat')
// Logic to export a unixfs directory.
module.exports = dirExporter

function dirExporter (cid, node, name, path, pathRest, resolve, size, dag, parent, depth, options) {
function dirExporter (cid, node, name, path, pathRest, resolve, dag, parent, depth, options) {
const accepts = pathRest[0]

const dir = {
name: name,
depth: depth,
path: path,
cid,
size: node.size,
size: 0,
type: 'dir'
}

Expand All @@ -32,7 +32,7 @@ function dirExporter (cid, node, name, path, pathRest, resolve, size, dag, paren
filter((item) => accepts === undefined || item.name === accepts),
map((link) => ({
depth: depth + 1,
size: link.size,
size: 0,
name: link.name,
path: path + '/' + link.name,
cid: link.cid,
Expand Down
4 changes: 2 additions & 2 deletions src/dir-hamt-sharded.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const waterfall = require('async/waterfall')
// Logic to export a unixfs directory.
module.exports = shardedDirExporter

function shardedDirExporter (cid, node, name, path, pathRest, resolve, size, dag, parent, depth, options) {
function shardedDirExporter (cid, node, name, path, pathRest, resolve, dag, parent, depth, options) {
let dir
if (!parent || (parent.path !== path)) {
dir = {
name: name,
depth: depth,
path: path,
cid,
size: node.size,
size: 0,
type: 'dir'
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const paramap = require('pull-paramap')
const extractDataFromBlock = require('./extract-data-from-block')

// Logic to export a single (possibly chunked) unixfs file.
module.exports = (cid, node, name, path, pathRest, resolve, size, dag, parent, depth, options) => {
module.exports = (cid, node, name, path, pathRest, resolve, dag, parent, depth, options) => {
const accepts = pathRest[0]

if (accepts !== undefined && accepts !== path) {
Expand All @@ -29,7 +29,7 @@ module.exports = (cid, node, name, path, pathRest, resolve, size, dag, parent, d
return error(err)
}

const fileSize = size || file.fileSize()
const fileSize = file.fileSize()

let offset = options.offset
let length = options.length
Expand Down
2 changes: 1 addition & 1 deletion src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const pull = require('pull-stream/pull')
const values = require('pull-stream/sources/values')
const error = require('pull-stream/sources/error')

module.exports = (cid, node, name, path, pathRest, resolve, size, dag, parent, depth) => {
module.exports = (cid, node, name, path, pathRest, resolve, dag, parent, depth) => {
let newNode
if (pathRest.length) {
const pathElem = pathRest[0]
Expand Down
4 changes: 2 additions & 2 deletions src/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ const empty = require('pull-stream/sources/empty')
const extractDataFromBlock = require('./extract-data-from-block')

// Logic to export a single raw block
module.exports = (cid, node, name, path, pathRest, resolve, size, dag, parent, depth, options) => {
module.exports = (cid, node, name, path, pathRest, resolve, dag, parent, depth, options) => {
const accepts = pathRest[0]

if (accepts !== undefined && accepts !== path) {
return empty()
}

size = size || node.length
const size = node.length

let offset = options.offset
let length = options.length
Expand Down
5 changes: 2 additions & 3 deletions src/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ function createResolver (dag, options, depth, parent) {
name: item.name,
path: item.path,
pathRest: item.pathRest,
size: item.size,
dag,
parentNode: item.parent || parent,
depth: item.depth,
options
})
}

function resolve ({ cid, node, name, path, pathRest, size, dag, parentNode, depth, options }) {
function resolve ({ cid, node, name, path, pathRest, dag, parentNode, depth, options }) {
let type

try {
Expand All @@ -83,7 +82,7 @@ function createResolver (dag, options, depth, parent) {

const resolveDeep = createResolver(dag, options, depth, node)

return nodeResolver(cid, node, name, path, pathRest, resolveDeep, size, dag, parentNode, depth, options)
return nodeResolver(cid, node, name, path, pathRest, resolveDeep, dag, parentNode, depth, options)
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/exporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ describe('exporter', () => {
),
({ cid, files: [ file ] }, cb) => {
expect(file).to.have.property('path', cid.toBaseEncodedString())
expect(file).to.have.property('size', ONE_MEG * 6)
fileEql(file, null, cb)
}
], done)
Expand Down Expand Up @@ -500,6 +501,12 @@ describe('exporter', () => {
`${cid.toBaseEncodedString()}/level-1/level-2`
])

files
.filter(file => file.type === 'dir')
.forEach(dir => {
expect(dir).to.has.property('size', 0)
})

pull(
pull.values(files),
pull.map((file) => Boolean(file.content)),
Expand Down