From b07fafb2f274c13f8257415cb540644c0b91c246 Mon Sep 17 00:00:00 2001 From: Nicolas JUHEL Date: Mon, 16 Oct 2023 11:33:32 +0200 Subject: [PATCH] Fix GZip & File/progress Package Archive/GZIP - remove call of getGunzipSize - expose to public the internal getGunZipSize => GetGunZipSize Package file/progress - fix nil function with progress, use empty function if function are nil --- archive/gzip/reader.go | 9 +-------- file/progress/progress.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/archive/gzip/reader.go b/archive/gzip/reader.go index e70293aa..ad7f09d8 100644 --- a/archive/gzip/reader.go +++ b/archive/gzip/reader.go @@ -35,17 +35,10 @@ import ( ) func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error { - var siz = getGunZipSize(src) - - if d, k := dst.(libfpg.Progress); k && siz > 0 { - d.Reset(siz) - } - if _, e := src.Seek(0, io.SeekStart); e != nil { return ErrorFileSeek.Error(e) } else if _, e = dst.Seek(0, io.SeekStart); e != nil { return ErrorFileSeek.Error(e) - } else if siz > 0 { } r, e := gz.NewReader(src) @@ -68,7 +61,7 @@ func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error { } } -func getGunZipSize(src io.ReadSeeker) int64 { +func GetGunZipSize(src io.ReadSeeker) int64 { if _, e := src.Seek(0, io.SeekStart); e != nil { return 0 } diff --git a/file/progress/progress.go b/file/progress/progress.go index d95fc9ff..b4f506f8 100644 --- a/file/progress/progress.go +++ b/file/progress/progress.go @@ -32,14 +32,26 @@ import ( ) func (o *progress) RegisterFctIncrement(fct FctIncrement) { + if fct == nil { + fct = func(size int64) {} + } + o.fi.Store(fct) } func (o *progress) RegisterFctReset(fct FctReset) { + if fct == nil { + fct = func(size, current int64) {} + } + o.fr.Store(fct) } func (o *progress) RegisterFctEOF(fct FctEOF) { + if fct == nil { + fct = func() {} + } + o.fe.Store(fct) }