# Copyright (c) 2020-now by the Zeek Project. See LICENSE for details.

module filter;

import spicy;

## A filter that performs zlib decompression.
type Zlib = unit(window_bits: optional<int64> = Null) {
    %filter;

    on %init {
        if ( window_bits )
            self.z = spicy::zlib_init(*window_bits);
    }

    : bytes &chunked &eod {
        self.forward(spicy::zlib_decompress(self.z, $$));
        }

    on %done {
        self.forward(spicy::zlib_finish(self.z));
        }

    var z: spicy::ZlibStream;
};

## A filter that performs Base64 decoding.
type Base64Decode = unit {
    %filter;

    : bytes &chunked &eod {
        self.forward(spicy::base64_decode(self.z, $$));
        }

    on %done {
        self.forward(spicy::base64_finish(self.z));
        }

    var z: spicy::Base64Stream;
};
