Skip to content

Commit 627d32e

Browse files
committed
Add example emulating some of isoinfo -lR
1 parent c0ea8db commit 627d32e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

examples/iso_info.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package examples
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
"path/filepath"
8+
9+
"github.com/diskfs/go-diskfs"
10+
"github.com/diskfs/go-diskfs/filesystem"
11+
"github.com/diskfs/go-diskfs/filesystem/iso9660"
12+
)
13+
14+
func PrintIsoInfo(isoPath string) {
15+
disk, err := diskfs.Open(isoPath)
16+
if err != nil {
17+
log.Fatal(err)
18+
}
19+
fs, err := disk.GetFilesystem(0)
20+
if err != nil {
21+
log.Fatal(err)
22+
}
23+
24+
err = fileInfoFor("/", fs)
25+
if err != nil {
26+
log.Fatalf("Failed to get file info: %s\n", err)
27+
}
28+
}
29+
30+
func fileInfoFor(path string, fs filesystem.FileSystem) error {
31+
files, err := fs.ReadDir(path)
32+
if err != nil {
33+
return err
34+
}
35+
36+
for _, file := range files {
37+
fullPath := filepath.Join(path, file.Name())
38+
if file.IsDir() {
39+
err = fileInfoFor(fullPath, fs)
40+
if err != nil {
41+
return err
42+
}
43+
continue
44+
}
45+
isoFile, err := fs.OpenFile(fullPath, os.O_RDONLY)
46+
if err != nil {
47+
fmt.Printf("Failed to open file %s: %v\n", fullPath, err)
48+
continue
49+
}
50+
51+
myFile := isoFile.(*iso9660.File)
52+
fmt.Printf("%s\n Size: %d\n Location: %d\n\n", fullPath, file.Size(), myFile.Location())
53+
}
54+
return nil
55+
}

0 commit comments

Comments
 (0)