diff --git a/internal/cmd/open.go b/internal/cmd/open.go index 616828d..4056c75 100644 --- a/internal/cmd/open.go +++ b/internal/cmd/open.go @@ -145,6 +145,7 @@ func openHandler(cmd *cobra.Command, args []string) { } w.Header().Set("Content-Type", contentType) + w.Header().Set("Content-Encoding", "gzip") if _, err = w.Write(content); err != nil { panic(err) } diff --git a/internal/cmd/update.go b/internal/cmd/update.go index 5254008..2564496 100644 --- a/internal/cmd/update.go +++ b/internal/cmd/update.go @@ -119,8 +119,7 @@ func updateHandler(cmd *cobra.Command, args []string) { // Check if user really want to batch update archive if nBook := len(bookmarks); nBook > 5 && !offline && !noArchival && !skipConfirm { - fmt.Println() - fmt.Printf("This update will also generate offline archive for %d bookmark(s).\n", nBook) + fmt.Printf("This update will generate offline archive for %d bookmark(s).\n", nBook) fmt.Println("This might take a long time and uses lot of your network bandwith.") confirmUpdate := "" @@ -130,6 +129,7 @@ func updateHandler(cmd *cobra.Command, args []string) { if confirmUpdate != "y" { fmt.Println("No bookmarks updated") return + } } diff --git a/pkg/warc/internal/archiver/archiver.go b/pkg/warc/internal/archiver/archiver.go index d3a91cc..2b8d38d 100644 --- a/pkg/warc/internal/archiver/archiver.go +++ b/pkg/warc/internal/archiver/archiver.go @@ -1,6 +1,8 @@ package archiver import ( + "bytes" + "compress/gzip" "fmt" "strings" "sync" @@ -147,7 +149,21 @@ func (arc *Archiver) archive(res ResourceURL) { // SaveToStorage save processing result to storage. func (arc *Archiver) SaveToStorage(result ProcessResult) error { - err := arc.DB.Batch(func(tx *bbolt.Tx) error { + // Compress content + buffer := bytes.NewBuffer(nil) + gzipper := gzip.NewWriter(buffer) + + _, err := gzipper.Write(result.Content) + if err != nil { + return fmt.Errorf("compress failed: %v", err) + } + + err = gzipper.Close() + if err != nil { + return fmt.Errorf("compress failed: %v", err) + } + + err = arc.DB.Batch(func(tx *bbolt.Tx) error { bucket := tx.Bucket([]byte(result.Name)) if bucket != nil { return nil @@ -158,7 +174,7 @@ func (arc *Archiver) SaveToStorage(result ProcessResult) error { return err } - err = bucket.Put([]byte("content"), result.Content) + err = bucket.Put([]byte("content"), buffer.Bytes()) if err != nil { return err }