2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-05-30 08:50:51 +00:00

Add new FileInputSource constructors

This commit is contained in:
Jay Berkenbilt 2022-05-04 12:02:39 -04:00
parent e259635986
commit e5f3910c3e
8 changed files with 28 additions and 12 deletions

View File

@ -1,5 +1,8 @@
2022-05-04 Jay Berkenbilt <ejb@ql.org> 2022-05-04 Jay Berkenbilt <ejb@ql.org>
* FileInputSource has new constructors that eliminate the need to
call setFilename or setFile in most cases.
* Enhance JSON by adding a write method that takes a Pipeline* and * Enhance JSON by adding a write method that takes a Pipeline* and
depth, and add several helper methods to make it easier to write depth, and add several helper methods to make it easier to write
large amounts of JSON incrementally without having to have the large amounts of JSON incrementally without having to have the

View File

@ -30,6 +30,10 @@ class QPDF_DLL_CLASS FileInputSource: public InputSource
QPDF_DLL QPDF_DLL
FileInputSource(); FileInputSource();
QPDF_DLL QPDF_DLL
FileInputSource(char const* filename);
QPDF_DLL
FileInputSource(char const* description, FILE* filep, bool close_file);
QPDF_DLL
void setFilename(char const* filename); void setFilename(char const* filename);
QPDF_DLL QPDF_DLL
void setFile(char const* description, FILE* filep, bool close_file); void setFile(char const* description, FILE* filep, bool close_file);

View File

@ -24,8 +24,8 @@ void
ClosedFileInputSource::before() ClosedFileInputSource::before()
{ {
if (0 == this->m->fis.get()) { if (0 == this->m->fis.get()) {
this->m->fis = std::make_shared<FileInputSource>(); this->m->fis =
this->m->fis->setFilename(this->m->filename.c_str()); std::make_shared<FileInputSource>(this->m->filename.c_str());
this->m->fis->seek(this->m->offset, SEEK_SET); this->m->fis->seek(this->m->offset, SEEK_SET);
this->m->fis->setLastOffset(this->last_offset); this->m->fis->setLastOffset(this->last_offset);
} }

View File

@ -23,6 +23,19 @@ FileInputSource::FileInputSource() :
{ {
} }
FileInputSource::FileInputSource(char const* filename) :
m(new Members(false))
{
setFilename(filename);
}
FileInputSource::FileInputSource(
char const* description, FILE* filep, bool close_file) :
m(new Members(false))
{
setFile(description, filep, close_file);
}
void void
FileInputSource::setFilename(char const* filename) FileInputSource::setFilename(char const* filename)
{ {

View File

@ -270,8 +270,7 @@ QPDF::~QPDF()
void void
QPDF::processFile(char const* filename, char const* password) QPDF::processFile(char const* filename, char const* password)
{ {
FileInputSource* fi = new FileInputSource(); FileInputSource* fi = new FileInputSource(filename);
fi->setFilename(filename);
processInputSource(std::shared_ptr<InputSource>(fi), password); processInputSource(std::shared_ptr<InputSource>(fi), password);
} }
@ -279,8 +278,7 @@ void
QPDF::processFile( QPDF::processFile(
char const* description, FILE* filep, bool close_file, char const* password) char const* description, FILE* filep, bool close_file, char const* password)
{ {
FileInputSource* fi = new FileInputSource(); FileInputSource* fi = new FileInputSource(description, filep, close_file);
fi->setFile(description, filep, close_file);
processInputSource(std::shared_ptr<InputSource>(fi), password); processInputSource(std::shared_ptr<InputSource>(fi), password);
} }

View File

@ -2445,9 +2445,9 @@ QPDFJob::handlePageSpecs(
cis->stayOpen(true); cis->stayOpen(true);
} else { } else {
QTC::TC("qpdf", "QPDFJob keep files open y"); QTC::TC("qpdf", "QPDFJob keep files open y");
FileInputSource* fis = new FileInputSource(); FileInputSource* fis =
new FileInputSource(page_spec.filename.c_str());
is = std::shared_ptr<InputSource>(fis); is = std::shared_ptr<InputSource>(fis);
fis->setFilename(page_spec.filename.c_str());
} }
std::shared_ptr<QPDF> qpdf_ph = std::shared_ptr<QPDF> qpdf_ph =
processInputSource(is, password, true); processInputSource(is, password, true);

View File

@ -73,8 +73,7 @@ main()
do_tests(&cf2); do_tests(&cf2);
cf2.stayOpen(false); cf2.stayOpen(false);
std::cout << "testing with FileInputSource\n"; std::cout << "testing with FileInputSource\n";
FileInputSource f; FileInputSource f("input");
f.setFilename("input");
do_tests(&f); do_tests(&f);
std::cout << "all assertions passed" << std::endl; std::cout << "all assertions passed" << std::endl;
return 0; return 0;

View File

@ -191,8 +191,7 @@ process(char const* filename, bool include_ignorable, size_t max_len)
std::shared_ptr<InputSource> is; std::shared_ptr<InputSource> is;
// Tokenize file, skipping streams // Tokenize file, skipping streams
FileInputSource* fis = new FileInputSource(); FileInputSource* fis = new FileInputSource(filename);
fis->setFilename(filename);
is = std::shared_ptr<InputSource>(fis); is = std::shared_ptr<InputSource>(fis);
dump_tokens(is, "FILE", max_len, include_ignorable, true, false); dump_tokens(is, "FILE", max_len, include_ignorable, true, false);