Import std.compress.lz4
std.compress.lz4
LZ4 compression, in its frame format.
LZ4's frame format, of .lz4 files, over LZ4. Its Compress and Decompress work at once, and its Compressor and Decompressor take bytes in turn and give what came out of them so far, for data that comes in parts. Levels go from 1, the fastest, which is the default, to 12, the smallest: 1 is LZ4's fast mode, 2 its middle one, 3 to 9 its high-compression mode, and 10 to 12 that mode's optimal parser. Each frame has its content's checksum, and a Compress's says its size. A Decompress reads frames one after another.
Examples
// Each format's Compressor and Decompressor take bytes in turn.
Local compressor = Lz4Compressor(1)
Local packed = compressor.Add("a part, and ".Bytes)
packed.AddAll(compressor.Add("the rest".Bytes))
packed.AddAll(compressor.Finish())
Local decompressor = Lz4Decompressor()
Local text = Try decompressor.Add(packed)
text.AddAll(Try decompressor.Finish())
Expect(String.FromUtf8(text) == "a part, and the rest")std/compress/lz4.fb
Types
Lz4
struct
Public Struct Lz4
LZ4's frames, which compress fast and decompress faster.
Examples
Local data = "fast, fast, fast, fast, fast".Repeated(100).Bytes
Local packed = Lz4.Compress(data)
Expect(packed.Count < data.Count)
Local unpacked = Try Lz4.Decompress(packed)
Expect(unpacked == data)-
@PanicsAtCaller Public Static Method Compress(data: UInt8[], level: Int = 1): UInt8[]static method #The
data, compressed at thelevel. Panics when thelevelisn't from 1 to 12. -
@PanicsAtCaller Public Static Method Decompress(data: UInt8[], limit: Int = MOST_BYTES): UInt8[] Throws IOErrorstatic method #The bytes the
datais compressed from, each frame's after the last's, or an IOError when it isn't Lz4's, ends early, or would come to more thanlimitbytes. Panics when thelimitis negative.
Lz4Compressor
class
Public Class Lz4Compressor Implements Coder
Lz4's bytes made in turn: Add gives what compressing the bytes it takes has made so far, and Finish what's left, which ends a frame, and starts again.
-
A new Lz4Compressor at the
level. Panics when it isn't from 1 to 12. -
Compresses
data, and gives the Lz4 bytes it has made so far, which can be none, as it holds some back to compress with what comes next. -
The rest of the bytes, which end the frame, and starts again, for another.
Lz4Decompressor
class
Public Class Lz4Decompressor Implements Coder
Lz4's bytes taken in turn, a frame after another: Add gives what the bytes it takes decompress to so far, and Finish what's left once they've all been added, and starts again. Each throws an IOError when the bytes aren't Lz4's or would come to more than the limit, and Finish when they end early.
-
A new Lz4Decompressor that gives at most
limitbytes. Panics when thelimitis negative. -
Decompresses
data, and gives the bytes it comes to so far. Throws an IOError when the bytes aren't Lz4's, or would come to more than the limit. -
The rest of the bytes, once every one is added, and starts again. Throws an IOError when the frame ended early.
Report an issue with this page or with FutureBlitz on GitHub.