22 #include "runtime.hpp"
29 FileSource::FileSource(
const char* fname, Source& source)
31 file_ = fopen(fname,
"rb");
32 if (file_)
get(source);
36 FileSource::~FileSource()
45 word32 FileSource::size(
bool use_current)
47 long current = ftell(file_);
51 fseek(file_, 0, SEEK_SET);
55 fseek(file_, 0, SEEK_END);
56 long end = ftell(file_);
58 fseek(file_, current, SEEK_SET);
64 word32 FileSource::size_left()
71 word32 FileSource::get(Source& source)
74 if (source.size() < sz)
77 size_t bytes = fread(source.buffer_.get_buffer(), 1, sz, file_);
86 FileSink::FileSink(
const char* fname, Source& source)
88 file_ = fopen(fname,
"wb");
89 if (file_) put(source);
101 void FileSink::put(Source& source)
103 fwrite(source.get_buffer(), 1, source.size(), file_);
108 void Source::reset(ByteBlock& otherBlock)
110 buffer_.Swap(otherBlock);