iceberg-cpp
Loading...
Searching...
No Matches
puffin_reader.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <cstddef>
26#include <cstdint>
27#include <memory>
28#include <optional>
29#include <utility>
30#include <vector>
31
34#include "iceberg/result.h"
35#include "iceberg/type_fwd.h"
36
37namespace iceberg::puffin {
38
42class ICEBERG_EXPORT PuffinReader {
43 public:
49 std::unique_ptr<InputFile> input_file,
50 std::optional<int64_t> footer_size = std::nullopt,
51 std::optional<int64_t> file_size = std::nullopt);
52
54
57
62 const BlobMetadata& blob_metadata);
63
67 const std::vector<BlobMetadata>& blobs);
68
70 Status Close();
71
72 private:
73 PuffinReader(std::unique_ptr<SeekableInputStream> stream, int64_t file_size,
74 std::optional<int64_t> known_footer_size);
75
76 Result<std::vector<std::byte>> ReadBytes(int64_t offset, int64_t length);
77 Result<int64_t> FooterSize();
78 Result<std::vector<std::byte>> ReadFooter(int64_t footer_size);
79
81 std::unique_ptr<SeekableInputStream> stream_;
83 int64_t file_size_;
85 std::optional<int64_t> known_footer_size_;
87 bool closed_ = false;
88};
89
90} // namespace iceberg::puffin
Reader for Puffin files.
Definition puffin_reader.h:42
Result< std::vector< std::pair< BlobMetadata, std::vector< std::byte > > > > ReadAll(const std::vector< BlobMetadata > &blobs)
Read all blobs described in the file metadata.
Result< std::pair< BlobMetadata, std::vector< std::byte > > > ReadBlob(const BlobMetadata &blob_metadata)
Read a specific blob's data by its metadata.
Result< FileMetadata > ReadFileMetadata()
Read and return the file metadata from the footer.
Status Close()
Close the underlying input stream.
static Result< std::unique_ptr< PuffinReader > > Make(std::unique_ptr< InputFile > input_file, std::optional< int64_t > footer_size=std::nullopt, std::optional< int64_t > file_size=std::nullopt)
Create a PuffinReader for the given input file.
Define symbol visibility macros for core Iceberg APIs.
Puffin file metadata, reader, and writer APIs.
Definition file_metadata.h:35
std::expected< T, E > Result
Result alias.
Definition result.h:88
Define Result, Status, and error helpers.
Metadata about a blob stored in a Puffin file footer.
Definition file_metadata.h:90