Search Unity

Question Does Unity have a compression API?

Discussion in 'Scripting' started by CodeSmile, Jun 4, 2023.

  1. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,001
    Seeing how many things can be compressed in so many ways (Gzip, LZ4, Brotli, etc. etc.) within Unity, it baffled me that I couldn't find any built-in API to hand over a byte[] and have it returned in a compressed format.

    Not even the in-development packages like Collections and Serialization have something like that (with the exception of "packing").

    Currently I just use .NET's GZipStream but I'm wondering if there's anything in the Unity-universe that's also readily available?

    ... and it needs to have a permissive license - not looking for asset store assets. But internal methods or github repositories with license are okay. I know ZipSharpLib but I was really hoping for something bursted & jobified.
     
    Last edited: Jun 4, 2023
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,001
    I found this delta compression algorithm which references this LZ4 algorithm for .NET. Here’s the Odin extension for it. LZ4 trades compression efficiency for speed.

    Since Unity provides LZ4 and LZ4HC as build compression options I'm pretty bummed that there isn't a public API available for this. I mean it's super-simple take some bytes and return some bytes stuff ...
     
  4. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    730
    adamgolden likes this.
  5. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    Nad_B likes this.
  6. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154