Forum Discussion

lance_6's avatar
lance_6
Helper II
4 years ago
Solved

Decompress Brotli Data

I'm working with an API that delivers payloads compressed using brotli. I've been looking for documentation on decompressing this in the Power Query Editor. Microsoft's documentation on this is non-existent and I can't figure out how to make it work. 

 

Here's roughly what I've got right now: 

 

let
    Source = Binary.Decompress(
                    Web.Contents(
                           "https://testURL.net/history/TestBrotli",
                           [Headers=[Authorization=#"myAPIkey"]]
                                ), 
                    Compression.Brotli
               )
in
    Source

 

 Does anyone have experience with this? Any pointers?

  • It seems like the Compression.Brotli argument isn't even implemented. I can't get it to work with a test example from here, even when entered in the most basic form.

  • Hi lance_6 ,

    Like I guessed, it only supports the two types which are introdcued in the document, here is the update from PG team:

     

    This is working as documented, the only compression types supported are as documented. Using any other types throws the appropriate Invalid compression type. 

     

    Best Regards,
    Community Support Team _ Yingjie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

7 Replies

  • It seems like the Compression.Brotli argument isn't even implemented. I can't get it to work with a test example from here, even when entered in the most basic form.

    • lance_6's avatar
      lance_6
      Helper II

      This is the same thing I found. Looks like although they have the `Compression.Brotli` function, they don't have it implemented and only accept the two options v-yingjl mentioned. Compression.GZip and Compression.Deflate

       

      I'm not sure why they would have the functions and not allow for them to be used. Very frustrating, Microsoft being Microsoft. 

  • v-yingjl's avatar
    v-yingjl
    Community Support

    Hi lance_6 ,

    Currently I have found some information on Binary.Decompress document:

     

    Perhaps it only supports .GZip and .Deflate type in Power Query Editor but not certain. I have submited this issue internal to confirm it(ICM: 296956165), would update here as soon as possible if there is any progress about it.

     

    Best Regards,
    Community Support Team _ Yingjie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • v-yingjl's avatar
    v-yingjl
    Community Support

    Hi lance_6 ,

    Like I guessed, it only supports the two types which are introdcued in the document, here is the update from PG team:

     

    This is working as documented, the only compression types supported are as documented. Using any other types throws the appropriate Invalid compression type. 

     

    Best Regards,
    Community Support Team _ Yingjie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • AlexisOlson's avatar
      AlexisOlson
      Super User

      The language "Compression types include:" doesn't necessarily mean the two listed examples are the only ones that work. There are public documentation pages for compression types Brotli, LZ4, Snappy, and Zstandard. Why do these pages exist if they aren't supported?

    • lance_6's avatar
      lance_6
      Helper II

      Thank you. This is frustrating and the other compression functions should definitely be either made functional or removed. 

  • Late to this one, but the conclusion above ("the codec isn't there") turns out to be only half right, and the half that's wrong is the useful half.

    Binary.Decompress really does implement just two of the seven members of Compression.Type: GZip and Deflate. Everything else fails at runtime, exactly as Alexis and lance_6 found in 2022, and that is still true today. But the engine itself is not missing Brotli. Parquet.Document decompresses Brotli, Snappy, Zstandard and LZ4 every time it opens a compressed Parquet file, so the codecs ship in the same mashup engine that refuses to expose them through Binary.Decompress.

    You can reach them with nothing but documented M. Wrap the compressed stream in a minimal, spec conformant Parquet file that declares one REQUIRED FIXED_LEN_BYTE_ARRAY(N) column with a single PLAIN encoded row, mark the page as Brotli compressed, and paste your stream in as the page body byte for byte. That schema is the one point in Parquet's design space where the uncompressed page is exactly the N payload bytes: REQUIRED drops definition and repetition levels, one row drops repetition, and the fixed length type drops the per value length prefixes. Hand the bytes to Parquet.Document, read the single cell back, and you have your decompressed blob. No custom connector, no external service, nothing leaves the engine.

    I packaged it as a drop in superset of Binary.Decompress, same argument convention:

    let
    Source = Codec.Decompress(
    Web.Contents(
    [Headers=[Authorization=#"myAPIkey"]]
    ),
    Compression.Brotli
    )
    in
    Source
    Function, probe and test fixtures are here, Apache 2.0: