diff --git a/internal/appherder/appimage.go b/internal/appherder/appimage.go index e33235c..f331c1e 100644 --- a/internal/appherder/appimage.go +++ b/internal/appherder/appimage.go @@ -125,10 +125,13 @@ func fileSystemOffset(file io.ReaderAt) (int64, error) { } } -// isSquashFS reports whether a SquashFS superblock begins at offset. -func isSquashFS(file interface { +// readerAt is the subset of io.ReaderAt used by filesystem detection helpers. +type readerAt interface { ReadAt([]byte, int64) (int, error) -}, offset int64) bool { +} + +// isSquashFS reports whether a SquashFS superblock begins at offset. +func isSquashFS(file readerAt, offset int64) bool { magic := make([]byte, 4) _, err := file.ReadAt(magic, offset) return err == nil && string(magic) == "hsqs" @@ -136,9 +139,7 @@ func isSquashFS(file interface { // scanForSquashFS searches for a SquashFS superblock in 4096-byte steps over // the next 64 MiB starting from offset. Returns the found position or false. -func scanForSquashFS(file interface { - ReadAt([]byte, int64) (int, error) -}, offset int64) (int64, bool) { +func scanForSquashFS(file readerAt, offset int64) (int64, bool) { const window = 64 * 1024 * 1024 buf := make([]byte, 4096) for pos := offset; pos < offset+window; pos += 4096 { diff --git a/internal/appherder/dwarfs.go b/internal/appherder/dwarfs.go index 548c303..c2dcfcb 100644 --- a/internal/appherder/dwarfs.go +++ b/internal/appherder/dwarfs.go @@ -56,9 +56,7 @@ func extractCommand(ctx context.Context, appimagePath, destDir string) *exec.Cmd } // isDwarFS reports whether the payload at offset starts with the DwarFS magic. -func isDwarFS(file interface { - ReadAt([]byte, int64) (int, error) -}, offset int64) bool { +func isDwarFS(file readerAt, offset int64) bool { magic := make([]byte, 6) _, err := file.ReadAt(magic, offset) return err == nil && string(magic) == "DWARFS"