diff --git a/package.json b/package.json index 03bea065..1545773f 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "safe-buffer": "^5.1.2" }, "dependencies": { - "protons": "^1.0.1" + "protons": "ipfs/protons#make-optional-values-optional" }, "contributors": [ "David Dias ", diff --git a/src/index.js b/src/index.js index 00dbf124..87baec7a 100644 --- a/src/index.js +++ b/src/index.js @@ -114,19 +114,19 @@ function Data (type, data) { } // decode from protobuf https://github.com/ipfs/go-ipfs/blob/master/unixfs/format.go#L24 -Data.unmarshal = (marsheled) => { - const decoded = unixfsData.decode(marsheled) +Data.unmarshal = (marshaled) => { + const decoded = unixfsData.decode(marshaled) if (!decoded.Data) { decoded.Data = undefined } const obj = new Data(types[decoded.Type], decoded.Data) obj.blockSizes = decoded.blocksizes - if (decoded.mode) { + if (decoded.mode !== undefined) { obj.mode = decoded.mode } - if (decoded.mtime) { + if (decoded.mtime !== undefined) { obj.mtime = decoded.mtime } diff --git a/test/unixfs-format.spec.js b/test/unixfs-format.spec.js index 0f352e76..7cdb64e6 100644 --- a/test/unixfs-format.spec.js +++ b/test/unixfs-format.spec.js @@ -112,6 +112,36 @@ describe('unixfs-format', () => { expect(unmarshalled.mode).to.equal(mode) }) + it('empty mode', () => { + const mode = 0 + const data = new UnixFS('file') + data.mode = mode + const marshalled = data.marshal() + const unmarshalled = UnixFS.unmarshal(marshalled) + expect(unmarshalled.mode).to.equal(mode) + }) + + it('default file mode', () => { + const data = new UnixFS('file') + const marshalled = data.marshal() + const unmarshalled = UnixFS.unmarshal(marshalled) + expect(unmarshalled.mode).to.equal(parseInt('0644', 8)) + }) + + it('default directory mode', () => { + const data = new UnixFS('directory') + const marshalled = data.marshal() + const unmarshalled = UnixFS.unmarshal(marshalled) + expect(unmarshalled.mode).to.equal(parseInt('0755', 8)) + }) + + it('default hamt-sharded-directory mode', () => { + const data = new UnixFS('directory') + const marshalled = data.marshal() + const unmarshalled = UnixFS.unmarshal(marshalled) + expect(unmarshalled.mode).to.equal(parseInt('0755', 8)) + }) + it('mtime', () => { const mtime = parseInt(Date.now() / 1000) const data = new UnixFS('file')