Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Go Test

on:
push:
branches:
- master
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- "1.18"
- "1.19"
- "1.20"
- "1.21"
- "1.22"
- "1.23"
- "1.24"
env:
GOLANGCI_LINT_VERSION: v1.64.5

steps:
- name: Install Go
if: success()
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v4

- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Run linter
uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}

- name: Run tests
run: go run gotest.tools/gotestsum@latest --junitfile tests.xml --format pkgname -- -cover -race ./...

- name: Test Summary
uses: test-summary/action@v2
with:
paths: "tests.xml"
if: always()
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
* Updated license to reflect current year (2025)

### Fixed
* Fix writer failure not being returned from `Patch` methods.
* Remove all usages of the now deprecated `io/ioutil` package.

## [1.0.2] - 2025-02-27
### Changed
* Update kingpin v2 import path.
Expand Down
5 changes: 2 additions & 3 deletions diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ package diff

import (
"io"
"io/ioutil"

"github.com/dsnet/compress/bzip2"
"github.com/icedream/go-bsdiff/internal"
"github.com/icedream/go-bsdiff/internal/native"
)

func Diff(oldReader, newReader io.Reader, patchWriter io.Writer) (err error) {
oldBytes, err := ioutil.ReadAll(oldReader)
oldBytes, err := io.ReadAll(oldReader)
if err != nil {
return
}
newBytes, err := ioutil.ReadAll(newReader)
newBytes, err := io.ReadAll(newReader)
if err != nil {
return
}
Expand Down
8 changes: 8 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Package bsdiff implements very high-level functionality to patch and diff two
* contents.
*
* This package relies on the bsdiff C code and hence requires cgo to be
* enabled.
*/
package bsdiff
8 changes: 5 additions & 3 deletions patch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ package patch
import (
"compress/bzip2"
"io"
"io/ioutil"

"github.com/icedream/go-bsdiff/internal"
"github.com/icedream/go-bsdiff/internal/native"
)

func Patch(oldReader io.Reader, newWriter io.Writer, patchReader io.Reader) (err error) {
oldBytes, err := ioutil.ReadAll(oldReader)
oldBytes, err := io.ReadAll(oldReader)
if err != nil {
return
}
Expand All @@ -29,7 +28,10 @@ func Patch(oldReader io.Reader, newWriter io.Writer, patchReader io.Reader) (err
bz2Reader := bzip2.NewReader(patchReader)

err = native.Patch(oldBytes, newBytes, bz2Reader)
if err != nil {
return err
}

newWriter.Write(newBytes)
_, err = newWriter.Write(newBytes)
return
}
5 changes: 2 additions & 3 deletions raw/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package diff

import (
"io"
"io/ioutil"

"github.com/icedream/go-bsdiff/internal/native"
)
Expand All @@ -20,11 +19,11 @@ It may be helpful to save away the new content size along with the actual
patch as it will be needed in order to reuse the patch.
*/
func Diff(oldReader, newReader io.Reader, patchWriter io.Writer) (err error) {
oldBytes, err := ioutil.ReadAll(oldReader)
oldBytes, err := io.ReadAll(oldReader)
if err != nil {
return
}
newBytes, err := ioutil.ReadAll(newReader)
newBytes, err := io.ReadAll(newReader)
if err != nil {
return
}
Expand Down
8 changes: 5 additions & 3 deletions raw/patch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package patch

import (
"io"
"io/ioutil"

"github.com/icedream/go-bsdiff/internal/native"
)
Expand All @@ -20,15 +19,18 @@ newSize needs to be exactly the size of the new file that should be generated
from the patch.
*/
func Patch(oldReader io.Reader, newWriter io.Writer, patchReader io.Reader, newSize uint64) (err error) {
oldBytes, err := ioutil.ReadAll(oldReader)
oldBytes, err := io.ReadAll(oldReader)
if err != nil {
return
}

newBytes := make([]byte, newSize)

err = native.Patch(oldBytes, newBytes, oldReader)
if err != nil {
return err
}

newWriter.Write(newBytes)
_, err = newWriter.Write(newBytes)
return
}
Loading