AppleHV - make gz ops sparse

gz by definition is not able to preserve the sparse nature of files.  using some code from the crc project and gluing it together with our decompression code, we can re-create the sparseness of a file.  one downside is the operation is a little bit slower, but i think the gains from the sparse file are well worth it in IO alone.

there are a number of todo's in this PR that would be ripe for quick hitting fixes.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <baude@redhat.com>
This commit is contained in:
Brent Baude
2024-02-04 08:32:41 -06:00
committed by Brent Baude
parent 85d8281484
commit d5eb8f3b71
5 changed files with 237 additions and 11 deletions

View File

@ -0,0 +1,52 @@
package compression
import (
"os"
"path/filepath"
"testing"
)
func TestCopyFile(t *testing.T) {
testStr := "test-machine"
srcFile, err := os.CreateTemp("", "machine-test-")
if err != nil {
t.Fatal(err)
}
srcFi, err := srcFile.Stat()
if err != nil {
t.Fatal(err)
}
_, _ = srcFile.Write([]byte(testStr)) //nolint:mirror
srcFile.Close()
srcFilePath := filepath.Join(os.TempDir(), srcFi.Name())
destFile, err := os.CreateTemp("", "machine-copy-test-")
if err != nil {
t.Fatal(err)
}
destFi, err := destFile.Stat()
if err != nil {
t.Fatal(err)
}
destFile.Close()
destFilePath := filepath.Join(os.TempDir(), destFi.Name())
if err := CopyFile(srcFilePath, destFilePath); err != nil {
t.Fatal(err)
}
data, err := os.ReadFile(destFilePath)
if err != nil {
t.Fatal(err)
}
if string(data) != testStr {
t.Fatalf("expected data \"%s\"; received \"%s\"", testStr, string(data))
}
}