mirror of
https://github.com/go-shiori/shiori.git
synced 2025-01-16 04:48:30 +08:00
Use gzip which make archive 1/3 smaller
This commit is contained in:
parent
b1464bd89b
commit
10ddb3fbbe
3 changed files with 21 additions and 4 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue