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

fix: do not stringify output of object data #1398

Merged
merged 1 commit into from
Jun 19, 2018
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
2 changes: 1 addition & 1 deletion src/cli/commands/object/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
throw err
}

print(data.toString(), false)
print(data, false)
})
}
}
24 changes: 24 additions & 0 deletions test/cli/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

const expect = require('chai').expect
const runOnAndOff = require('../utils/on-and-off')
const UnixFs = require('ipfs-unixfs')
const path = require('path')
const fs = require('fs')
const crypto = require('crypto')
const os = require('os')

describe('object', () => runOnAndOff((thing) => {
let ipfs
Expand Down Expand Up @@ -64,6 +69,25 @@ describe('object', () => runOnAndOff((thing) => {
})
})

it('unaulterated data', () => {
// has to be big enough to span several DAGNodes
const data = crypto.randomBytes(1024 * 300)
const file = path.join(os.tmpdir(), `file-${Math.random()}.txt`)

fs.writeFileSync(file, data)

return ipfs(`add ${file}`)
.then((out) => {
return ipfs.raw(`object data ${out.split(' ')[1]}`)
})
.then((out) => {
const meta = UnixFs.unmarshal(out)

expect(meta.type).to.equal('file')
expect(meta.fileSize()).to.equal(data.length)
})
})

it('links', () => {
return ipfs('object links QmZZmY4KCu9r3e7M2Pcn46Fc5qbn6NpzaAGaYb22kbfTqm').then((out) => {
expect(out).to.eql(
Expand Down
15 changes: 13 additions & 2 deletions test/utils/ipfs-exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ module.exports = (repoPath, opts) => {
}, opts)

const exec = (args) => execa(`${process.cwd()}/src/cli/bin.js`, args, config)
const execRaw = (args) => execa(`${process.cwd()}/src/cli/bin.js`, args, Object.assign({}, config, {
encoding: null
}))

function ipfs () {
let args = Array.from(arguments)
const execute = (exec, args) => {
if (args.length === 1) {
args = args[0].split(' ')
}
Expand All @@ -51,6 +53,15 @@ module.exports = (repoPath, opts) => {
return res
}

function ipfs () {
return execute(exec, Array.from(arguments))
}

// Will return buffers instead of strings
ipfs.raw = function () {
return execute(execRaw, Array.from(arguments))
}

/**
* Expect the command passed as @param arguments to fail.
* @return {Promise} Resolves if the command passed as @param arguments fails,
Expand Down