-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.go
More file actions
56 lines (48 loc) · 1.22 KB
/
example.go
File metadata and controls
56 lines (48 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"log"
)
// Example demonstrates how to use the RemoteZipFile library
func ExampleUsage() {
// Example 1: List files in a remote ZIP
fmt.Println("Example 1: List files")
rzf, err := NewRemoteZipFile("https://example.com/archive.zip")
if err != nil {
log.Fatal(err)
}
files := rzf.List()
fmt.Printf("Found %d files:\n", len(files))
for _, name := range files {
fmt.Printf(" - %s\n", name)
}
// Example 2: Get detailed file information
fmt.Println("\nExample 2: File details")
for _, f := range rzf.Files() {
fmt.Printf("%s: %d bytes (compressed: %d bytes)\n",
f.Name, f.UncompressedSize64, f.CompressedSize64)
}
// Example 3: Extract a specific file to memory
fmt.Println("\nExample 3: Extract file")
data, err := rzf.Extract("README.txt")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Extracted %d bytes\n", len(data))
fmt.Printf("Content preview: %s\n", data[:min(100, len(data))])
// Example 4: Stream a file
fmt.Println("\nExample 4: Stream file")
rc, err := rzf.Open("data.json")
if err != nil {
log.Fatal(err)
}
defer rc.Close()
// Read from rc as needed...
fmt.Println("File opened successfully")
}
func min(a, b int) int {
if a < b {
return a
}
return b
}