Skip to content

Commit 5625556

Browse files
feat: disable chunking and remove all content function
1 parent adbec90 commit 5625556

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

dag/dag.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,26 +224,30 @@ func processFile(entry fs.DirEntry, fullPath string, path *string, dag *DagBuild
224224
builder.SetType(FileLeafType)
225225
fileChunks := chunkFile(fileData, ChunkSize)
226226

227-
if len(fileChunks) == 1 {
228-
builder.SetData(fileChunks[0])
227+
if ChunkSize <= 0 {
228+
builder.SetData(fileData)
229229
} else {
230-
for i, chunk := range fileChunks {
231-
chunkEntryPath := filepath.Join(relPath, strconv.Itoa(i))
232-
chunkBuilder := CreateDagLeafBuilder(chunkEntryPath)
230+
if len(fileChunks) == 1 {
231+
builder.SetData(fileChunks[0])
232+
} else {
233+
for i, chunk := range fileChunks {
234+
chunkEntryPath := filepath.Join(relPath, strconv.Itoa(i))
235+
chunkBuilder := CreateDagLeafBuilder(chunkEntryPath)
233236

234-
chunkBuilder.SetType(ChunkLeafType)
235-
chunkBuilder.SetData(chunk)
237+
chunkBuilder.SetType(ChunkLeafType)
238+
chunkBuilder.SetData(chunk)
236239

237-
// Chunks don't get custom metadata
238-
chunkLeaf, err := chunkBuilder.BuildLeaf(nil)
239-
if err != nil {
240-
return nil, err
241-
}
240+
// Chunks don't get custom metadata
241+
chunkLeaf, err := chunkBuilder.BuildLeaf(nil)
242+
if err != nil {
243+
return nil, err
244+
}
242245

243-
label := dag.GetNextAvailableLabel()
244-
builder.AddLink(label, chunkLeaf.Hash)
245-
chunkLeaf.SetLabel(label)
246-
dag.AddLeaf(chunkLeaf, nil)
246+
label := dag.GetNextAvailableLabel()
247+
builder.AddLink(label, chunkLeaf.Hash)
248+
chunkLeaf.SetLabel(label)
249+
dag.AddLeaf(chunkLeaf, nil)
250+
}
247251
}
248252
}
249253

@@ -973,3 +977,9 @@ func (d *Dag) ApplyTransmissionPacket(packet *TransmissionPacket) {
973977
}
974978
}
975979
}
980+
981+
func (d *Dag) RemoveAllContent() {
982+
for _, leaf := range d.Leafs {
983+
leaf.Content = nil
984+
}
985+
}

dag/types.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"github.com/HORNET-Storage/Scionic-Merkle-Tree/merkletree"
77
)
88

9-
var ChunkSize = 2048 * 1024 // 2048 * 1024 bytes = 2 megabytes
9+
const DefaultChunkSize = 2048 * 1024 // 2048 * 1024 bytes = 2 megabytes
10+
11+
var ChunkSize = DefaultChunkSize
1012

1113
type LeafType string
1214

@@ -80,3 +82,11 @@ type TransmissionPacket struct {
8082
func SetChunkSize(size int) {
8183
ChunkSize = size
8284
}
85+
86+
func DisableChunking() {
87+
SetChunkSize(-1)
88+
}
89+
90+
func SetDefaultChunkSize() {
91+
SetChunkSize(DefaultChunkSize)
92+
}

0 commit comments

Comments
 (0)