Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strings"
"sync"
"sync/atomic"
"time"
"unicode/utf8"

"github.com/klauspost/compress/zip"
Expand Down Expand Up @@ -206,13 +205,6 @@ func fileInfoHeader(name string, fi os.FileInfo, hdr *zip.FileHeader) {
if hdr.Mode().IsDir() {
hdr.Name += "/"
}

const uint32max = (1 << 32) - 1
if hdr.UncompressedSize64 > uint32max {
hdr.UncompressedSize = uint32max
} else {
hdr.UncompressedSize = uint32(hdr.UncompressedSize64)
}
}

func (a *Archiver) createDirectory(fi os.FileInfo, hdr *zip.FileHeader) error {
Expand Down Expand Up @@ -345,7 +337,6 @@ func (a *Archiver) createHeaderRaw(fi os.FileInfo, fh *zip.FileHeader) (io.Write
fh.ReaderVersion = zipVersion20

if !fh.Modified.IsZero() {
fh.ModifiedDate, fh.ModifiedTime = timeToMsDosTime(fh.Modified)
fh.Extra = append(fh.Extra, zipextra.NewExtendedTimestamp(fh.Modified).Encode()...)
}

Expand All @@ -368,10 +359,3 @@ func detectUTF8(s string) (valid, require bool) {
}
return true, require
}

// https://github.com/golang/go/blob/go1.17.7/src/archive/zip/struct.go#L242
func timeToMsDosTime(t time.Time) (fDate uint16, fTime uint16) {
fDate = uint16(t.Day() + int(t.Month())<<5 + (t.Year()-1980)<<9)
fTime = uint16(t.Second()/2 + t.Minute()<<5 + t.Hour()<<11)
return
}
21 changes: 10 additions & 11 deletions archiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"sort"
"slices"
"strings"
"testing"
"time"
Expand All @@ -34,7 +33,7 @@ func testCreateFiles(t *testing.T, files map[string]testFile) (map[string]os.Fil
for path := range files {
filenames = append(filenames, path)
}
sort.Strings(filenames)
slices.Sort(filenames)

var err error
for _, path := range filenames {
Expand Down Expand Up @@ -70,7 +69,7 @@ func testCreateFiles(t *testing.T, files map[string]testFile) (map[string]os.Fil
}

func testCreateArchive(t *testing.T, dir string, files map[string]os.FileInfo, fn func(filename, chroot string), opts ...ArchiverOption) {
f, err := ioutil.TempFile("", "fastzip-test")
f, err := os.CreateTemp("", "fastzip-test")
require.NoError(t, err)
defer os.Remove(f.Name())
defer f.Close()
Expand Down Expand Up @@ -146,7 +145,7 @@ func TestArchiveCancelContext(t *testing.T) {
files, dir := testCreateFiles(t, testFiles)
defer os.RemoveAll(dir)

f, err := ioutil.TempFile("", "fastzip-test")
f, err := os.CreateTemp("", "fastzip-test")
require.NoError(t, err)
defer os.Remove(f.Name())
defer f.Close()
Expand Down Expand Up @@ -192,7 +191,7 @@ func TestArchiveWithCompressor(t *testing.T) {
files, dir := testCreateFiles(t, testFiles)
defer os.RemoveAll(dir)

f, err := ioutil.TempFile("", "fastzip-test")
f, err := os.CreateTemp("", "fastzip-test")
require.NoError(t, err)
defer os.Remove(f.Name())
defer f.Close()
Expand All @@ -219,7 +218,7 @@ func TestArchiveWithMethod(t *testing.T) {
files, dir := testCreateFiles(t, testFiles)
defer os.RemoveAll(dir)

f, err := ioutil.TempFile("", "fastzip-test")
f, err := os.CreateTemp("", "fastzip-test")
require.NoError(t, err)
defer os.Remove(f.Name())
defer f.Close()
Expand All @@ -246,7 +245,7 @@ func TestArchiveWithStageDirectory(t *testing.T) {
defer os.RemoveAll(chroot)

dir := t.TempDir()
f, err := ioutil.TempFile("", "fastzip-test")
f, err := os.CreateTemp("", "fastzip-test")
require.NoError(t, err)
defer os.Remove(f.Name())
defer f.Close()
Expand Down Expand Up @@ -288,7 +287,7 @@ func TestArchiveWithConcurrency(t *testing.T) {

for _, test := range concurrencyTests {
func() {
f, err := ioutil.TempFile("", "fastzip-test")
f, err := os.CreateTemp("", "fastzip-test")
require.NoError(t, err)
defer os.Remove(f.Name())
defer f.Close()
Expand Down Expand Up @@ -338,7 +337,7 @@ func TestArchiveWithBufferSize(t *testing.T) {

for _, test := range tests {
func() {
f, err := ioutil.TempFile("", "fastzip-test")
f, err := os.CreateTemp("", "fastzip-test")
require.NoError(t, err)
defer os.Remove(f.Name())
defer f.Close()
Expand Down Expand Up @@ -415,7 +414,7 @@ func TestArchiveWithOffset(t *testing.T) {
files, dir := testCreateFiles(t, testFiles)
defer os.RemoveAll(dir)

f, err := ioutil.TempFile("", "fastzip-test")
f, err := os.CreateTemp("", "fastzip-test")
require.NoError(t, err)
defer os.Remove(f.Name())
defer f.Close()
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module github.com/saracen/fastzip

go 1.18
go 1.23.1

require (
github.com/klauspost/compress v1.16.5
github.com/klauspost/compress v1.17.10
github.com/saracen/zipextra v0.0.0-20220303013732-0187cb0159ea
github.com/stretchr/testify v1.8.3
golang.org/x/sync v0.2.0
golang.org/x/sys v0.8.0
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.8.0
golang.org/x/sys v0.26.0
)

require (
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI=
github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0=
github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/saracen/zipextra v0.0.0-20220303013732-0187cb0159ea h1:8czYLkvzZRE+AElIQeDffQdgR+CC3wKEFILYU/1PeX4=
github.com/saracen/zipextra v0.0.0-20220303013732-0187cb0159ea/go.mod h1:hnzuad9d2wdd3z8fC6UouHQK5qZxqv3F/E6MMzXc7q0=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down