Skip to content

having trouble decompressing data compressed by Apple's LZ4 #270

Open

Description

@wtholliday

I'm compressing random data using NSMutableData (in Swift) as follows:

import Foundation

let n = 1024
let numbers = (0..<n).map { _ in UInt8.random(in: 0...1) }

print("generated random data: \(numbers)")

let data = Data(numbers)
let mutable = NSMutableData(data: data)
try! mutable.compress(using: .lz4)

print("compressed size: \(mutable.count)")'

try! mutable.write(toFile: "compressed.dat", options: [])

And reading into python using:

import os
import lz4.frame

fh = open('compressed.dat', 'rb')
ba = bytearray(fh.read())

print("read %d bytes" % len(ba))

decompressed = lz4.frame.decompress(ba)

print("decompressed to %d bytes" % len(decompressed))

When calling lz4.frame.decompress, I get:

RuntimeError: LZ4F_getFrameInfo failed with code: ERROR_frameType_unknown

trying lz4.block.decompress, I get:

_block.LZ4BlockError: Decompression failed: corrupt input or insufficient space in destination buffer. Error code: 4

If you aren't on a Mac, here's the file generated by the swift code:

compressed.dat.zip

Activity

  1. Mantas-Skackauskas commented on Apr 17, 2024

    @Mantas-Skackauskas

    Hi @wtholliday. Have you managed to resolve the issue? I'm having the exact same problem. Cheers.

  2. wtholliday commented on Apr 17, 2024

    @wtholliday
    Author
  3. Mantas-Skackauskas commented on Apr 17, 2024

    @Mantas-Skackauskas

    Thanks for providing more info. Apple should provide better documentation IMO.

    Anyway, I resorted to using LZFSE compression which seem to work fine outside of Apple platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions