Is the zip writer concurrent? #945
-
Hi, i would like to ask if it is possible to make a archive writer concurrently for performance reasons. Currently, package main
import (
"bytes"
"fmt"
"io"
"sync"
"github.com/google/uuid"
"github.com/klauspost/compress/zip"
)
func main() {
buf := new(bytes.Buffer)
zw := zip.NewWriter(buf)
wg := new(sync.WaitGroup)
r := 512
wg.Add(r)
for i := 0; i < r; i++ {
go func() {
defer wg.Done()
r, err := zw.Create(uuid.New().String())
if err != nil {
panic(err)
}
if _, err := io.WriteString(r, uuid.New().String()); err != nil {
panic(err)
}
}()
}
wg.Wait()
if err := zw.Close(); err != nil {
panic(err)
}
fmt.Printf("wrote %d", len(buf.Bytes()))
} Is it possible to make a archive with a concurrent writer, and if there isn't, are there any alternatives? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
@apprehensions No. There is no concurrent zip writer that I know of. The only thing I see making sense being concurrent would be the deflate part, since each file needs to be written serially. If you know you are only writing small files I guess you can do the deflate in separate goroutines and use a fan-in to add the compressed data with CreateRaw. But it is not something I have explored too deeply. |
Beta Was this translation helpful? Give feedback.
@apprehensions No. There is no concurrent zip writer that I know of.
The only thing I see making sense being concurrent would be the deflate part, since each file needs to be written serially. If you know you are only writing small files I guess you can do the deflate in separate goroutines and use a fan-in to add the compressed data with CreateRaw. But it is not something I have explored too deeply.