Skip to content

Commit fa1d43c

Browse files
pgtedaviddias
authored andcommitted
WIP: Support for dir sharding (#14)
* protocol changes to support HAMT sharding * expose HAMT Shard data type * unixfs data for sharded dirs
1 parent 942e0e3 commit fa1d43c

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const types = [
1111
'directory',
1212
'file',
1313
'metadata',
14-
'symlink'
14+
'symlink',
15+
'hamt-sharded-directory'
1516
]
1617

1718
function Data (type, data) {
@@ -56,6 +57,7 @@ function Data (type, data) {
5657
case 'file': type = unixfsData.DataType.File; break
5758
case 'metadata': type = unixfsData.DataType.Metadata; break
5859
case 'symlink': type = unixfsData.DataType.Symlink; break
60+
case 'hamt-sharded-directory': type = unixfsData.DataType.HAMTShard; break
5961
default:
6062
throw new Error(`Unkown type: "${this.type}"`)
6163
}
@@ -69,7 +71,9 @@ function Data (type, data) {
6971
Type: type,
7072
Data: this.data,
7173
filesize: fileSize,
72-
blocksizes: this.blockSizes.length > 0 ? this.blockSizes : undefined
74+
blocksizes: this.blockSizes.length > 0 ? this.blockSizes : undefined,
75+
hashType: this.hashType,
76+
fanout: this.fanout
7377
})
7478
}
7579
}

src/unixfs.proto.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ module.exports = `message Data {
77
File = 2;
88
Metadata = 3;
99
Symlink = 4;
10+
HAMTShard = 5;
1011
}
1112
1213
required DataType Type = 1;
1314
optional bytes Data = 2;
1415
optional uint64 filesize = 3;
1516
repeated uint64 blocksizes = 4;
17+
18+
optional uint64 hashType = 5;
19+
optional uint64 fanout = 6;
1620
}
1721
1822
message Metadata {

test/unixfs-format.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ describe('unixfs-format', () => {
3434
done()
3535
})
3636

37+
it('hamt-sharded-directory', (done) => {
38+
const data = new UnixFS('hamt-sharded-directory')
39+
const marsheled = data.marshal()
40+
const unmarsheled = UnixFS.unmarshal(marsheled)
41+
expect(data.type).to.equal(unmarsheled.type)
42+
expect(data.data).to.deep.equal(unmarsheled.data)
43+
expect(data.blockSizes).to.deep.equal(unmarsheled.blockSizes)
44+
expect(data.fileSize()).to.deep.equal(unmarsheled.fileSize())
45+
done()
46+
})
47+
3748
it('file', (done) => {
3849
const data = new UnixFS('file', new Buffer('batata'))
3950
const marsheled = data.marshal()

0 commit comments

Comments
 (0)