Skip to content

Commit

Permalink
fix(*): [BREAKING] updated content length size to be 8 bytes instead …
Browse files Browse the repository at this point in the history
…of 4
  • Loading branch information
Nickersoft committed Jan 8, 2021
1 parent 80ca45c commit 639dbab
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions go/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ func LoadDictionary(inputPath string, newIndex bool) models.Dictionary {
// Read the compressed content size in bytes
file.Seek(7, 0)

contentSizeBytes := make([]byte, 4)
contentSizeBytes := make([]byte, 8)
_, contentSizeError := file.Read(contentSizeBytes)

Check(contentSizeError)
file.Seek(11, 0)
file.Seek(15, 0)

// Decode bytes for signature, version, and contentSize
signature := string(sigBytes)
version := binary.LittleEndian.Uint16(versionBytes)
contentSize := binary.LittleEndian.Uint32(contentSizeBytes)
contentSize := binary.LittleEndian.Uint64(contentSizeBytes)

// Assert signature
Assert(signature == "ODICT", "Invalid file signature")
Expand Down
8 changes: 4 additions & 4 deletions go/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func Uint16ToBytes(n uint16) []byte {
return bytes
}

// Uint32ToBytes converts a uint32 type to a byte array
func Uint32ToBytes(n uint32) []byte {
bytes := make([]byte, 4)
// Uint64ToBytes converts a uint64 type to a byte array
func Uint64ToBytes(n uint64) []byte {
bytes := make([]byte, 8)

// TODO: normalize
binary.LittleEndian.PutUint32(bytes, uint32(n))
binary.LittleEndian.PutUint64(bytes, uint64(n))

return bytes
}
6 changes: 3 additions & 3 deletions go/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ func createODictFile(outputPath string, dictionary models.Dictionary) {

signature := []byte("ODICT")
version := Uint16ToBytes(2)
compressedSize := uint32(len(compressed))
compressedSizeBytes := Uint32ToBytes(compressedSize)
compressedSize := uint64(len(compressed))
compressedSizeBytes := Uint64ToBytes(compressedSize)

writer := bufio.NewWriter(file)

Expand All @@ -296,7 +296,7 @@ func createODictFile(outputPath string, dictionary models.Dictionary) {

Assert(sigBytes == 5, "Signature bytes do not equal 5")
Assert(versionBytes == 2, "Version bytes do not equal 2")
Assert(contentSizeBytes == 4, "Content byte count does not equal 4")
Assert(contentSizeBytes == 8, "Content byte count does not equal 8")
Assert(contentBytes == int(compressedSize), "Content does not equal the computed byte count")

writer.Flush()
Expand Down

0 comments on commit 639dbab

Please sign in to comment.