Forráskód Böngészése

Add ability to see timestamp and size of bundled files

spsobole 1 éve
szülő
commit
5a1b0ff2b3
2 módosított fájl, 34 hozzáadás és 4 törlés
  1. 16 1
      bundle.go
  2. 18 3
      cmd/vesselcmd/main.go

+ 16 - 1
bundle.go

@@ -5,6 +5,7 @@ import (
 	"encoding/binary"
 	"fmt"
 	"io"
+	"io/fs"
 	"os"
 	"path/filepath"
 	"strings"
@@ -42,7 +43,7 @@ func (b *Bundle) Version() uint64 {
 	return b.version
 }
 
-// Version returns the bundles version info
+// List lists files in the bundle
 func (b *Bundle) List() []string {
 	zr, err := zip.NewReader(b, b.Size())
 
@@ -58,6 +59,20 @@ func (b *Bundle) List() []string {
 	return files
 }
 
+func (b *Bundle) FileInfo() map[string]fs.FileInfo {
+	zr, err := zip.NewReader(b, b.Size())
+
+	if err != nil {
+		return nil
+	}
+
+	files := make(map[string]fs.FileInfo)
+	for idx := range zr.File {
+		files[zr.File[idx].Name] = zr.File[idx].FileInfo()
+	}
+	return files
+}
+
 // ReadAt implements io.ReaderAt
 func (b *Bundle) ReadAt(p []byte, off int64) (n int, err error) {
 	off += b.offset

+ 18 - 3
cmd/vesselcmd/main.go

@@ -43,7 +43,7 @@ func main() {
 	default:
 		help()
 
-	case "info":
+	case "list":
 		parms.Parse(os.Args[2:])
 
 		b, err := vessel.Open(*bundleFlag)
@@ -54,8 +54,23 @@ func main() {
 		fmt.Printf("Bundle Size:    %d\n", b.Size())
 		fmt.Printf("Bundle Version: %x\n", b.Version())
 		files := b.List()
-		for _, name := range files {
-			fmt.Printf("  %s\n", name)
+		for _, file := range files {
+			fmt.Printf("  %s\n", file)
+		}
+
+	case "info":
+		parms.Parse(os.Args[2:])
+
+		b, err := vessel.Open(*bundleFlag)
+		if err != nil {
+			panic(fmt.Errorf("%s: %w", *bundleFlag, err))
+		}
+		defer b.Close()
+		fmt.Printf("Bundle Size:    %d\n", b.Size())
+		fmt.Printf("Bundle Version: %x\n", b.Version())
+		files := b.FileInfo()
+		for path, file := range files {
+			fmt.Printf("  %v  %10d  %s\n", file.ModTime().UTC(), file.Size(), path)
 		}
 		// print contents