Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for sending docs and attachments as compressed deltas #683

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -16,6 +16,9 @@
[submodule "src/github.com/gorilla/context"]
path = src/github.com/gorilla/context
url = https://github.com/gorilla/context
[submodule "src/github.com/snej/zdelta-go"]
path = src/github.com/snej/zdelta-go
url = https://github.com/snej/zdelta-go.git
[submodule "src/github.com/tleyden/fakehttp"]
path = src/github.com/tleyden/fakehttp
url = https://github.com/tleyden/fakehttp.git
Expand Down
23 changes: 22 additions & 1 deletion src/github.com/couchbase/sync_gateway/base/util.go
Expand Up @@ -10,12 +10,13 @@
package base

import (
"strconv"
"compress/gzip"
"crypto/rand"
"encoding/json"
"fmt"
"io"
"regexp"
"strconv"
"strings"
"sync"
)
Expand Down Expand Up @@ -143,3 +144,23 @@ func (v *IntMax) SetIfMax(value int64) {
v.i = value
}
}

//////// GZIP WRITER CACHE:

var zipperCache sync.Pool

// Gets a gzip writer from the pool, or creates a new one if the pool is empty:
func GetGZipWriter(writer io.Writer) *gzip.Writer {
if gz, ok := zipperCache.Get().(*gzip.Writer); ok {
gz.Reset(writer)
return gz
} else {
return gzip.NewWriter(writer)
}
}

// Closes a gzip writer and returns it to the pool:
func ReturnGZipWriter(gz *gzip.Writer) {
gz.Close()
zipperCache.Put(gz)
}