Android-cuttlefish cvd tool
lz4_legacy.h
Go to the documentation of this file.
1//
2// Copyright (C) 2026 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#pragma once
17
18#include <memory>
19
20#include "cuttlefish/io/io.h"
22
23namespace cuttlefish {
24
25constexpr uint32_t kLz4LegacyFrameBlockSize = 8 << 20;
26
27// Handles the LZ4 Legacy frame format, used by the linux kernel.
28//
29// https://github.com/lz4/lz4/blob/5c4c1fb2354133e1f3b087a341576985f8114bd5/doc/lz4_Frame_format.md#legacy-frame
30
31Result<std::unique_ptr<Reader>> Lz4LegacyReader(std::unique_ptr<Reader>);
32
33// LZ4 Legacy frames are terminated by a 4-byte 0 length block. This
34// implementation handles this by assuming that any write call with a size less
35// than or equal to the block size (8 MB) is intended to be the last block in
36// the frame. Subsequent writes will fail after the last block is written.
37//
38// Because of this, callers should prefer WriteExact with this writer instead
39// of Copy, to avoid premature termination from small writes.
40Result<std::unique_ptr<Writer>> Lz4LegacyWriter(std::unique_ptr<Writer>);
41
42} // namespace cuttlefish
Definition: alloc_driver.h:20
Result< std::unique_ptr< Writer > > Lz4LegacyWriter(std::unique_ptr< Writer > sink)
Definition: lz4_legacy.cc:126
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30
Result< std::unique_ptr< Reader > > Lz4LegacyReader(std::unique_ptr< Reader > source)
Definition: lz4_legacy.cc:118
constexpr uint32_t kLz4LegacyFrameBlockSize
Definition: lz4_legacy.h:25