aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2024-03-28 16:20:51 +0200
committerMarin Ivanov <[email protected]>2024-03-28 16:20:51 +0200
commitd0c92f7cb3bb581db84dede75c53269868d5eed1 (patch)
treeb5dfeb82c0d06e2c39510bcff4b6cf88837ea89a
Initial commit
-rw-r--r--go.mod5
-rw-r--r--go.sum2
-rw-r--r--main.go91
3 files changed, 98 insertions, 0 deletions
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..daf52cb
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,5 @@
+module go.metala.org/zipreads
+
+go 1.21.5
+
+require github.com/spf13/pflag v1.0.5
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..287f6fa
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,2 @@
+github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
+github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..0167f9f
--- /dev/null
+++ b/main.go
@@ -0,0 +1,91 @@
+package main
+
+import (
+ "log"
+ "os"
+ "time"
+
+ flag "github.com/spf13/pflag"
+)
+
+// Compression methods.
+const (
+ Store uint16 = 0 // no compression
+ Deflate uint16 = 8 // DEFLATE compressed
+)
+
+const (
+ fileHeaderSignature = 0x04034b50
+ fileHeaderLen = 30 // + filename + extra
+)
+
+type FileHeader struct {
+ // Name is the name of the file.
+ //
+ // It must be a relative path, not start with a drive letter (such as "C:"),
+ // and must use forward slashes instead of back slashes. A trailing slash
+ // indicates that this file is a directory and should have no data.
+ //
+ // When reading zip files, the Name field is populated from
+ // the zip file directly and is not validated for correctness.
+ // It is the caller's responsibility to sanitize it as
+ // appropriate, including canonicalizing slash directions,
+ // validating that paths are relative, and preventing path
+ // traversal through filenames ("../../../").
+ Name string
+
+ // Comment is any arbitrary user-defined string shorter than 64KiB.
+ Comment string
+
+ // NonUTF8 indicates that Name and Comment are not encoded in UTF-8.
+ //
+ // By specification, the only other encoding permitted should be CP-437,
+ // but historically many ZIP readers interpret Name and Comment as whatever
+ // the system's local character encoding happens to be.
+ //
+ // This flag should only be set if the user intends to encode a non-portable
+ // ZIP file for a specific localized region. Otherwise, the Writer
+ // automatically sets the ZIP format's UTF-8 flag for valid UTF-8 strings.
+ NonUTF8 bool
+
+ CreatorVersion uint16
+ ReaderVersion uint16
+ Flags uint16
+
+ // Method is the compression method. If zero, Store is used.
+ Method uint16
+
+ // Modified is the modified time of the file.
+ //
+ // When reading, an extended timestamp is preferred over the legacy MS-DOS
+ // date field, and the offset between the times is used as the timezone.
+ // If only the MS-DOS date is present, the timezone is assumed to be UTC.
+ //
+ // When writing, an extended timestamp (which is timezone-agnostic) is
+ // always emitted. The legacy MS-DOS date field is encoded according to the
+ // location of the Modified time.
+ Modified time.Time
+ ModifiedTime uint16 // Deprecated: Legacy MS-DOS date; use Modified instead.
+ ModifiedDate uint16 // Deprecated: Legacy MS-DOS time; use Modified instead.
+
+ CRC32 uint32
+ CompressedSize uint32 // Deprecated: Use CompressedSize64 instead.
+ UncompressedSize uint32 // Deprecated: Use UncompressedSize64 instead.
+ CompressedSize64 uint64
+ UncompressedSize64 uint64
+ Extra []byte
+ ExternalAttrs uint32 // Meaning depends on CreatorVersion
+}
+
+func main() {
+ var filename string
+ flag.StringVarP(&filename, "filename", "f", "", "filename")
+ flag.Parse()
+
+ f, err := os.Open(filename)
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer f.Close()
+
+}