From 458687d543a03b6e6a74d2a6a20b5b8bc81062d8 Mon Sep 17 00:00:00 2001 From: Gilbert Chen Date: Fri, 3 May 2019 11:33:16 -0400 Subject: [PATCH] The cat command doesn't need to load the entire file into memory It can print out the chunk as soon as a chunk is retrieved. This avoids reconstructing the file in the memory which can be an issue with large files. --- src/duplicacy_snapshotmanager.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/duplicacy_snapshotmanager.go b/src/duplicacy_snapshotmanager.go index f39e412..383990a 100644 --- a/src/duplicacy_snapshotmanager.go +++ b/src/duplicacy_snapshotmanager.go @@ -1285,15 +1285,14 @@ func (manager *SnapshotManager) PrintFile(snapshotID string, revision int, path } file := manager.FindFile(snapshot, path, false) - var content []byte - if !manager.RetrieveFile(snapshot, file, func(chunk []byte) { content = append(content, chunk...) }) { + if !manager.RetrieveFile(snapshot, file, func(chunk []byte) { + fmt.Printf("%s", chunk) + }) { LOG_ERROR("SNAPSHOT_RETRIEVE", "File %s is corrupted in snapshot %s at revision %d", path, snapshot.ID, snapshot.Revision) return false } - fmt.Printf("%s", string(content)) - return true }