2024-01-01 15:55:55 +00:00
|
|
|
// Copyright (c) 2005-2024 Jay Berkenbilt
|
2018-06-22 16:15:22 +00:00
|
|
|
//
|
|
|
|
// This file is part of qpdf.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
|
|
// in compliance with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under
|
|
|
|
// the License.
|
|
|
|
//
|
|
|
|
// Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic
|
|
|
|
// License. At your option, you may continue to consider qpdf to be licensed under those terms.
|
|
|
|
// Please see the manual for additional information.
|
|
|
|
|
2018-08-12 18:07:22 +00:00
|
|
|
#ifndef QPDF_CLOSEDFILEINPUTSOURCE_HH
|
|
|
|
#define QPDF_CLOSEDFILEINPUTSOURCE_HH
|
2018-06-22 16:15:22 +00:00
|
|
|
|
|
|
|
// This is an input source that reads from files, like FileInputSource, except that it opens and
|
2023-05-29 18:26:18 +00:00
|
|
|
// closes the file surrounding every operation. This decreases efficiency, but it allows many more
|
|
|
|
// of these to exist at once than the maximum number of open file descriptors. This is used for
|
|
|
|
// merging large numbers of files.
|
2018-06-22 16:15:22 +00:00
|
|
|
|
|
|
|
#include <qpdf/InputSource.hh>
|
2022-09-23 19:15:39 +00:00
|
|
|
#include <qpdf/PointerHolder.hh> // unused -- remove in qpdf 12 (see #785)
|
2018-06-22 16:15:22 +00:00
|
|
|
|
2022-02-06 16:40:24 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2018-06-22 16:15:22 +00:00
|
|
|
class FileInputSource;
|
|
|
|
|
2022-04-10 13:29:11 +00:00
|
|
|
class QPDF_DLL_CLASS ClosedFileInputSource: public InputSource
|
2018-06-22 16:15:22 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
QPDF_DLL
|
|
|
|
ClosedFileInputSource(char const* filename);
|
|
|
|
QPDF_DLL
|
2023-06-01 14:21:32 +00:00
|
|
|
~ClosedFileInputSource() override;
|
2018-06-22 16:15:22 +00:00
|
|
|
QPDF_DLL
|
2023-06-01 14:21:32 +00:00
|
|
|
qpdf_offset_t findAndSkipNextEOL() override;
|
2018-06-22 16:15:22 +00:00
|
|
|
QPDF_DLL
|
2023-06-01 14:21:32 +00:00
|
|
|
std::string const& getName() const override;
|
2018-06-22 16:15:22 +00:00
|
|
|
QPDF_DLL
|
2023-06-01 14:21:32 +00:00
|
|
|
qpdf_offset_t tell() override;
|
2018-06-22 16:15:22 +00:00
|
|
|
QPDF_DLL
|
2023-06-01 14:21:32 +00:00
|
|
|
void seek(qpdf_offset_t offset, int whence) override;
|
2018-06-22 16:15:22 +00:00
|
|
|
QPDF_DLL
|
2023-06-01 14:21:32 +00:00
|
|
|
void rewind() override;
|
2018-06-22 16:15:22 +00:00
|
|
|
QPDF_DLL
|
2023-06-01 14:21:32 +00:00
|
|
|
size_t read(char* buffer, size_t length) override;
|
2018-06-22 16:15:22 +00:00
|
|
|
QPDF_DLL
|
2023-06-01 14:21:32 +00:00
|
|
|
void unreadCh(char ch) override;
|
2018-06-22 16:15:22 +00:00
|
|
|
|
2018-08-04 23:50:21 +00:00
|
|
|
// The file stays open between calls to stayOpen(true) and stayOpen(false). You can use this to
|
|
|
|
// surround multiple operations on a single ClosedFileInputSource to reduce the overhead of a
|
|
|
|
// separate open/close on each call.
|
|
|
|
QPDF_DLL
|
|
|
|
void stayOpen(bool);
|
|
|
|
|
2018-06-22 16:15:22 +00:00
|
|
|
private:
|
2020-04-03 16:04:54 +00:00
|
|
|
ClosedFileInputSource(ClosedFileInputSource const&) = delete;
|
|
|
|
ClosedFileInputSource& operator=(ClosedFileInputSource const&) = delete;
|
2018-06-22 16:15:22 +00:00
|
|
|
|
2022-04-10 17:29:10 +00:00
|
|
|
QPDF_DLL_PRIVATE
|
2018-06-22 16:15:22 +00:00
|
|
|
void before();
|
2022-04-10 17:29:10 +00:00
|
|
|
QPDF_DLL_PRIVATE
|
2018-06-22 16:15:22 +00:00
|
|
|
void after();
|
|
|
|
|
2022-08-25 13:23:53 +00:00
|
|
|
std::string filename;
|
|
|
|
qpdf_offset_t offset;
|
|
|
|
std::shared_ptr<FileInputSource> fis;
|
|
|
|
bool stay_open;
|
2018-06-22 16:15:22 +00:00
|
|
|
};
|
|
|
|
|
2018-08-12 18:07:22 +00:00
|
|
|
#endif // QPDF_CLOSEDFILEINPUTSOURCE_HH
|