aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/ClosedFileInputSource.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-08-05 01:50:21 +0200
committerJay Berkenbilt <ejb@ql.org>2018-08-05 01:52:46 +0200
commit4f4c627b77a169e1729982fa03dd75d5035f0297 (patch)
tree50230823b7f82e2ffe059684dec1858f06b5be73 /libqpdf/ClosedFileInputSource.cc
parent7855e18ae2f535f7e1b6fa396e298511e66e6f94 (diff)
downloadqpdf-4f4c627b77a169e1729982fa03dd75d5035f0297.tar.zst
ClosedFileInputSource: add method to keep file open
During periods of intensive operation on a specific file, this method can reduce the overhead of repeated open/close operations.
Diffstat (limited to 'libqpdf/ClosedFileInputSource.cc')
-rw-r--r--libqpdf/ClosedFileInputSource.cc21
1 files changed, 20 insertions, 1 deletions
diff --git a/libqpdf/ClosedFileInputSource.cc b/libqpdf/ClosedFileInputSource.cc
index ea79a840..63357886 100644
--- a/libqpdf/ClosedFileInputSource.cc
+++ b/libqpdf/ClosedFileInputSource.cc
@@ -4,7 +4,8 @@
ClosedFileInputSource::Members::Members(char const* filename) :
filename(filename),
offset(0),
- fis(0)
+ fis(0),
+ stay_open(false)
{
}
@@ -42,6 +43,10 @@ ClosedFileInputSource::after()
{
this->last_offset = this->m->fis->getLastOffset();
this->m->offset = this->m->fis->tell();
+ if (this->m->stay_open)
+ {
+ return;
+ }
delete this->m->fis;
this->m->fis = 0;
}
@@ -82,6 +87,10 @@ void
ClosedFileInputSource::rewind()
{
this->m->offset = 0;
+ if (this->m->fis)
+ {
+ this->m->fis->rewind();
+ }
}
size_t
@@ -101,3 +110,13 @@ ClosedFileInputSource::unreadCh(char ch)
// Don't call after -- the file has to stay open after this
// operation.
}
+
+void
+ClosedFileInputSource::stayOpen(bool val)
+{
+ this->m->stay_open = val;
+ if ((! val) && this->m->fis)
+ {
+ after();
+ }
+}