aboutsummaryrefslogtreecommitdiff
path: root/nix/mozlz4.nix
blob: 1fa0497f1fdd2a867215fe95387544475b606713 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{ pkgs, lib }:

let
  inherit (pkgs.writers) writePython3;
  inherit (pkgs.python3Packages) lz4;
in rec {
  compress = writePython3 "compress.py" { libraries = [ lz4 ]; } ''
    import sys
    import lz4.block

    data = lz4.block.compress(sys.stdin.buffer.read())
    data = b'mozLz40\0' + data

    sys.stdout.buffer.write(data)
  '';

  decompress = writePython3 "decompress.py" { libraries = [ lz4 ]; } ''
    import sys
    import lz4.block

    sys.stdin.buffer.read(8)
    sys.stdout.buffer.write(lz4.block.decompress(sys.stdin.buffer.read()))
  '';
}