aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/OffsetInputSource.cc
blob: 2923c388fdeb0a1217cb1292f08a22132a36f0e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <qpdf/OffsetInputSource.hh>

OffsetInputSource::OffsetInputSource(PointerHolder<InputSource> proxied,
                                     qpdf_offset_t global_offset) :
    proxied(proxied),
    global_offset(global_offset)
{
}

OffsetInputSource::~OffsetInputSource()
{
}

qpdf_offset_t
OffsetInputSource::findAndSkipNextEOL()
{
    return this->proxied->findAndSkipNextEOL() - this->global_offset;
}

std::string const&
OffsetInputSource::getName() const
{
    return this->proxied->getName();
}

qpdf_offset_t
OffsetInputSource::tell()
{
    return this->proxied->tell() - this->global_offset;
}

void
OffsetInputSource::seek(qpdf_offset_t offset, int whence)
{
    if (whence == SEEK_SET)
    {
        this->proxied->seek(offset + global_offset, whence);
    }
    else
    {
        this->proxied->seek(offset, whence);
    }
}

void
OffsetInputSource::rewind()
{
    seek(0, SEEK_SET);
}

size_t
OffsetInputSource::read(char* buffer, size_t length)
{
    size_t result = this->proxied->read(buffer, length);
    this->setLastOffset(this->proxied->getLastOffset() - global_offset);
    return result;
}

void
OffsetInputSource::unreadCh(char ch)
{
    this->proxied->unreadCh(ch);
}