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
23
24namespace cuttlefish {
25
26constexpr uint32_t kLz4LegacyFrameBlockSize = 8 << 20;
27
28// Handles the LZ4 Legacy frame format, used by the linux kernel.
29//
30// https://github.com/lz4/lz4/blob/5c4c1fb2354133e1f3b087a341576985f8114bd5/doc/lz4_Frame_format.md#legacy-frame
31
32Result<std::unique_ptr<Reader>> Lz4LegacyReader(std::unique_ptr<Reader>);
33
34// LZ4 Legacy frames are terminated by a 4-byte 0 length block. This
35// implementation handles this by assuming that any write call with a size less
36// than or equal to the block size (8 MB) is intended to be the last block in
37// the frame. Subsequent writes will fail after the last block is written.
38//
39// Because of this, callers should prefer WriteExact with this writer instead
40// of Copy, to avoid premature termination from small writes.
41Result<std::unique_ptr<Writer>> Lz4LegacyWriter(std::unique_ptr<Writer>);
42
43} // namespace cuttlefish
Definition: alloc_driver.h:21
Result< std::unique_ptr< Writer > > Lz4LegacyWriter(std::unique_ptr< Writer > sink)
Definition: lz4_legacy.cc:142
Result< std::unique_ptr< Reader > > Lz4LegacyReader(std::unique_ptr< Reader > source)
Definition: lz4_legacy.cc:134
tl::expected< T, StackTraceError< E > > Result
Definition: result_type.h:30
constexpr uint32_t kLz4LegacyFrameBlockSize
Definition: lz4_legacy.h:26