Skip to content

Commit

Permalink
Merge pull request #140 from SaveTheRbtz/rbtz/splitPackages
Browse files Browse the repository at this point in the history
go: split into multiple modules
  • Loading branch information
SaveTheRbtz authored Jul 24, 2024
2 parents 10872a2 + f9012f4 commit 7672f8a
Show file tree
Hide file tree
Showing 29 changed files with 79 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
go-version: '>=1.19'
check-latest: true
- name: Run coverage
working-directory: ./pkg
run: go test -coverprofile=coverage.out -covermode=count
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v4
13 changes: 8 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
go-version: ['1.22']

dir: ['pkg', 'cmd/zstdseek']
steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
Expand All @@ -23,10 +23,13 @@ jobs:
cache-dependency-path: go.sum
- name: Display Go version
run: go version
- name: Install dependencies
- name: Install dependencies (${{ matrix.dir }})
working-directory: ./${{ matrix.dir }}
run: |
go get .
- name: Build
- name: Build (${{ matrix.dir }})
working-directory: ./${{ matrix.dir }}
run: go build -v ./...
- name: Test with the Go CLI
run: go test
- name: Test (${{ matrix.dir }})
working-directory: ./${{ matrix.dir }}
run: go test -v ./...
1 change: 1 addition & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ jobs:
uses: golangci/[email protected]
with:
version: latest
working-directory: ./pkg
12 changes: 4 additions & 8 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
before:
hooks:
- go mod tidy
builds:
- env:
- id: zstdseek
main: ./
dir: ./cmd/zstdseek
env:
- CGO_ENABLED=0
goos:
- linux
Expand All @@ -12,10 +12,6 @@ builds:
goarch:
- amd64
- arm64
main: ./cmd/zstdseek
archives:
- replacements:
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
This library provides a random access reader (using uncompressed file offsets) for ZSTD-compressed streams. This can be used for creating transparent compression layers. Coupled with Content Defined Chunking (CDC) it can also be used as a robust de-duplication layer.
## Installation

`go get -u github.com/SaveTheRbtz/zstd-seekable-format-go`
`go get -u github.com/SaveTheRbtz/zstd-seekable-format-go/pkg`

## Using the seekable format

Writing is done through the `Writer` interface:
```go
import (
"github.com/klauspost/compress/zstd"
seekable "github.com/SaveTheRbtz/zstd-seekable-format-go"
seekable "github.com/SaveTheRbtz/zstd-seekable-format-go/pkg"
)

enc, err := zstd.NewWriter(nil, zstd.WithEncoderLevel(zstd.SpeedFastest))
Expand Down
19 changes: 19 additions & 0 deletions cmd/zstdseek/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module github.com/SaveTheRbtz/zstd-seekable-format-go/cmd/zstdseek

go 1.22

replace github.com/SaveTheRbtz/zstd-seekable-format-go/pkg => ../../pkg

require (
github.com/SaveTheRbtz/fastcdc-go v0.3.0
github.com/SaveTheRbtz/zstd-seekable-format-go/pkg v0.0.0-00010101000000-000000000000
github.com/klauspost/compress v1.17.9
go.uber.org/zap v1.27.0
)

require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/google/btree v1.1.2 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
)
24 changes: 24 additions & 0 deletions cmd/zstdseek/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
github.com/SaveTheRbtz/fastcdc-go v0.3.0 h1:JdHvLlnijDuisYIwpRDcHZEjbxvCqtEmJ3gf35VJBgA=
github.com/SaveTheRbtz/fastcdc-go v0.3.0/go.mod h1:2kMKqvBv1h9wCaUfETqsVkSESsCiFhp4YyEHyz7/SfE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=
github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion cmd/zstdseek/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/klauspost/compress/zstd"
"go.uber.org/zap"

seekable "github.com/SaveTheRbtz/zstd-seekable-format-go"
seekable "github.com/SaveTheRbtz/zstd-seekable-format-go/pkg"
)

type readCloser struct {
Expand Down
2 changes: 1 addition & 1 deletion decoder.go → pkg/decoder.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seekable

import (
"github.com/SaveTheRbtz/zstd-seekable-format-go/env"
"github.com/SaveTheRbtz/zstd-seekable-format-go/pkg/env"
)

// Decoder is a byte-oriented API that is useful for cases where wrapping io.ReadSeeker is not desirable.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion example_test.go → pkg/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/klauspost/compress/zstd"

seekable "github.com/SaveTheRbtz/zstd-seekable-format-go"
seekable "github.com/SaveTheRbtz/zstd-seekable-format-go/pkg"
)

func Example() {
Expand Down
5 changes: 2 additions & 3 deletions go.mod → pkg/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module github.com/SaveTheRbtz/zstd-seekable-format-go
module github.com/SaveTheRbtz/zstd-seekable-format-go/pkg

go 1.19
go 1.22

require (
github.com/SaveTheRbtz/fastcdc-go v0.3.0
github.com/cespare/xxhash/v2 v2.3.0
github.com/google/btree v1.1.2
github.com/klauspost/compress v1.17.9
Expand Down
5 changes: 1 addition & 4 deletions go.sum → pkg/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
github.com/SaveTheRbtz/fastcdc-go v0.3.0 h1:JdHvLlnijDuisYIwpRDcHZEjbxvCqtEmJ3gf35VJBgA=
github.com/SaveTheRbtz/fastcdc-go v0.3.0/go.mod h1:2kMKqvBv1h9wCaUfETqsVkSESsCiFhp4YyEHyz7/SfE=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -17,6 +13,7 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
Expand Down
2 changes: 1 addition & 1 deletion reader.go → pkg/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"go.uber.org/atomic"
"go.uber.org/zap"

"github.com/SaveTheRbtz/zstd-seekable-format-go/env"
"github.com/SaveTheRbtz/zstd-seekable-format-go/pkg/env"
)

type cachedFrame struct {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion reader_options.go → pkg/reader_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package seekable
import (
"go.uber.org/zap"

"github.com/SaveTheRbtz/zstd-seekable-format-go/env"
"github.com/SaveTheRbtz/zstd-seekable-format-go/pkg/env"
)

type rOption func(*readerImpl) error
Expand Down
2 changes: 1 addition & 1 deletion reader_test.go → pkg/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/klauspost/compress/zstd"
"github.com/stretchr/testify/assert"

"github.com/SaveTheRbtz/zstd-seekable-format-go/env"
"github.com/SaveTheRbtz/zstd-seekable-format-go/pkg/env"
)

const sourceString = "testtest2"
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions seekable_test.go → pkg/seekable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/klauspost/compress/zstd"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type bytesErr struct {
Expand Down Expand Up @@ -64,19 +65,19 @@ func TestIntercompat(t *testing.T) {
assert.NoError(t, err)

for _, fn := range []string{
// t2sz README.md -l 22 -s 1024 -o testdata/intercompat-t2sz.zst
"testdata/intercompat-t2sz.zst",
// t2sz README.md -l 22 -s 1024 -o intercompat-t2sz.zst
"intercompat-t2sz.zst",
// go run ./cmd/zstdseek -- \
// -f $(realpath README.md) -o $(realpath testdata/intercompat-zstdseek_v0.zst) \
// -f $(realpath README.md) -o $(realpath intercompat-zstdseek_v0.zst) \
// -c 1:1 -t -q 13
"testdata/intercompat-zstdseek_v0.zst",
"intercompat-zstdseek_v0.zst",
} {
fn := fn
t.Run(fn, func(t *testing.T) {
t.Parallel()

f, err := os.Open(fn)
assert.NoError(t, err)
f, err := os.Open(fmt.Sprintf("../testdata/%s", fn))
require.NoError(t, err)
defer f.Close()

r, err := NewReader(f, dec)
Expand Down
2 changes: 1 addition & 1 deletion writer.go → pkg/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/SaveTheRbtz/zstd-seekable-format-go/env"
"github.com/SaveTheRbtz/zstd-seekable-format-go/pkg/env"
)

// writerEnvImpl is the environment implementation of for the underlying WriteCloser.
Expand Down
2 changes: 1 addition & 1 deletion writer_options.go → pkg/writer_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package seekable
import (
"go.uber.org/zap"

"github.com/SaveTheRbtz/zstd-seekable-format-go/env"
"github.com/SaveTheRbtz/zstd-seekable-format-go/pkg/env"
)

type wOption func(*writerImpl) error
Expand Down
2 changes: 1 addition & 1 deletion writer_test.go → pkg/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/binary"
"fmt"
"io"
"math/rand"
"crypto/rand"
"testing"

"github.com/klauspost/compress/zstd"
Expand Down

0 comments on commit 7672f8a

Please sign in to comment.