diff --git a/src/cli/commands/object/data.js b/src/cli/commands/object/data.js index f47cad4035..13d0bfa7c7 100644 --- a/src/cli/commands/object/data.js +++ b/src/cli/commands/object/data.js @@ -17,7 +17,7 @@ module.exports = { throw err } - print(data.toString(), false) + print(data, false) }) } } diff --git a/test/cli/object.js b/test/cli/object.js index 4c69f7b770..df49543a65 100644 --- a/test/cli/object.js +++ b/test/cli/object.js @@ -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 @@ -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( diff --git a/test/utils/ipfs-exec.js b/test/utils/ipfs-exec.js index 2437f136a9..38742b76b5 100644 --- a/test/utils/ipfs-exec.js +++ b/test/utils/ipfs-exec.js @@ -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(' ') } @@ -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,