Android-cuttlefish cvd tool
seekable_source.h
Go to the documentation of this file.
1//
2// Copyright (C) 2025 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 <stddef.h>
19#include <stdint.h>
20
21#include <memory>
22
26#include "cuttlefish/io/io.h"
28
29namespace cuttlefish {
30
32 public:
33 friend class ReadableZip;
34 friend class WritableZipSource;
35
37 std::unique_ptr<SeekableZipSourceCallback>);
38
40 ~SeekableZipSource() override = default;
42
43 /* Returns a RAII instance that puts this instance in an "open for reading"
44 * state. Can fail. Should not outlive this instance. */
46
47 protected:
49};
50
51/* A `SeekableZipSource` in an "open for reading" state. */
53 public:
54 friend class SeekableZipSource;
55
59
60 Result<void> Visit(IoVisitor&) override;
61
62 Result<uint64_t> Read(void* data, uint64_t length) override;
63 Result<uint64_t> PRead(void* buf, uint64_t count,
64 uint64_t offset) const override;
65
66 Result<uint64_t> SeekSet(uint64_t offset) override;
67 Result<uint64_t> SeekCur(int64_t offset) override;
68 Result<uint64_t> SeekEnd(int64_t offset) override;
69
70 private:
71 Result<uint64_t> Seek(int64_t offset, int whence);
72
74};
75
77 SeekableZipSource inner);
78
79} // namespace cuttlefish
Definition: io.h:106
Definition: readable_source.h:37
Definition: archive.h:35
Definition: io.h:60
Definition: seekable_source.h:31
static Result< SeekableZipSource > FromCallbacks(std::unique_ptr< SeekableZipSourceCallback >)
Definition: seekable_source.cc:120
SeekableZipSource(SeekableZipSource &&)=default
~SeekableZipSource() override=default
SeekableZipSource & operator=(SeekableZipSource &&)=default
Result< class SeekingZipSourceReader > Reader()
Definition: seekable_source.cc:136
Definition: seekable_source.h:52
Result< uint64_t > Read(void *data, uint64_t length) override
Definition: seekable_source.cc:170
SeekingZipSourceReader(SeekingZipSourceReader &&)
Result< uint64_t > SeekCur(int64_t offset) override
Definition: seekable_source.cc:162
Result< uint64_t > SeekEnd(int64_t offset) override
Definition: seekable_source.cc:166
Result< void > Visit(IoVisitor &) override
Definition: seekable_source.cc:153
Result< uint64_t > Seek(int64_t offset, int whence)
Definition: seekable_source.cc:177
SeekingZipSourceReader & operator=(SeekingZipSourceReader &&)
Result< uint64_t > PRead(void *buf, uint64_t count, uint64_t offset) const override
Definition: seekable_source.cc:191
Result< uint64_t > SeekSet(uint64_t offset) override
Definition: seekable_source.cc:158
Definition: writable_source.h:30
Definition: readable_source.h:67
friend class SeekingZipSourceReader
Definition: readable_source.h:70
#define data
Definition: dict.c:56
Definition: alloc_driver.h:20
Result< std::unique_ptr< ReaderSeeker > > ZipSourceAsReaderSeeker(SeekableZipSource inner)
Definition: seekable_source.cc:198
std::unique_ptr< zip_source_t, ZipDeleter > ManagedZipSource
Definition: managed.h:37
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30