Skip to content
Open
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
25 changes: 6 additions & 19 deletions lzop/lzop.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,15 @@ func WriteHeader(buff *bytes.Buffer, fileTime int64, fileName string) error {
func WriteBytes(buff *bytes.Buffer, data []byte, compressionFunction func([]byte) []byte) error {
blockSize := 256 * 1024

if len(data) < blockSize {
blockSize = len(data)
}

iterations := len(data) / blockSize
for i := 0; i < iterations+1; i++ {

var compressed []byte
var unCompressed []byte

leftOver := len(data) - (i * blockSize)
if leftOver < blockSize {
unCompressed = data[(i * blockSize):]
} else {
unCompressed = data[(i * blockSize):((i + 1) * blockSize)]
}
for i, n := 0, len(data); i < n; i += blockSize {
j := i + blockSize

if len(unCompressed) == 0 {
continue
if j > n {
j = n
}

compressed = compressionFunction(unCompressed)
unCompressed := data[i:j]
compressed := compressionFunction(unCompressed)

// did you actually compress anything?
//this is to stop the compression library from sticking in extra
Expand Down
1 change: 1 addition & 0 deletions lzop/lzop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func testData(input []byte, buff *bytes.Buffer) {
}

func TestRandomDataSizes(t *testing.T) {
testData(getData(0), nil)
testData(getData(256), nil)
testData(getData(512), nil)
testData(getData(1024), nil)
Expand Down