5 #ifndef CRYPTOPP_IMPORTS
13 #if CRYPTOPP_DEBUG && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
14 void Files_TestInstantiations()
28 const char *fileName = NULL;
29 #if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400
30 const wchar_t *fileNameWide = NULL;
31 if (!parameters.
GetValue(Name::InputFileNameWide(), fileNameWide))
33 if (!parameters.
GetValue(Name::InputFileName(), fileName))
35 parameters.
GetValue(Name::InputStreamPointer(), m_stream);
39 std::ios::openmode binary = parameters.
GetValueWithDefault(Name::InputBinaryMode(),
true) ? std::ios::binary : std::ios::openmode(0);
40 m_file.reset(
new std::ifstream);
41 #ifdef CRYPTOPP_UNIX_AVAILABLE
44 fileName = (narrowed =
StringNarrow(fileNameWide)).c_str();
49 m_file->open(fileNameWide, std::ios::in | binary);
56 m_file->open(fileName, std::ios::in | binary);
58 throw OpenErr(fileName);
60 m_stream = m_file.get();
68 std::streampos current = m_stream->tellg();
69 std::streampos end = m_stream->seekg(0, std::ios::end).tellg();
70 m_stream->seekg(current);
82 lword size=transferBytes;
88 while (size && m_stream->good())
91 size_t spaceSize = 1024;
94 m_stream->read((
char *)m_space, (
unsigned int)
STDMIN(size, (lword)spaceSize));
96 m_len = (size_t)m_stream->gcount();
100 m_waiting = blockedBytes > 0;
104 transferBytes += m_len;
107 if (!m_stream->good() && !m_stream->eof())
118 if (begin == 0 && end == 1)
120 int result = m_stream->peek();
121 if (result == std::char_traits<char>::eof())
125 size_t blockedBytes = target.
ChannelPut(channel,
byte(result), blocking);
126 begin += 1-blockedBytes;
132 std::streampos current = m_stream->tellg();
133 std::streampos endPosition = m_stream->seekg(0, std::ios::end).tellg();
134 std::streampos newPosition = current +
static_cast<std::streamoff
>(begin);
136 if (newPosition >= endPosition)
138 m_stream->seekg(current);
141 m_stream->seekg(newPosition);
145 lword copyMax = end-begin;
146 size_t blockedBytes =
const_cast<FileStore *
>(
this)->
TransferTo2(target, copyMax, channel, blocking);
150 const_cast<FileStore *
>(
this)->m_waiting =
false;
157 m_stream->seekg(current);
161 m_stream->seekg(current);
171 lword oldPos = m_stream->tellg();
172 std::istream::off_type offset;
175 m_stream->seekg(offset, std::ios::cur);
176 return (lword)m_stream->tellg() - oldPos;
184 const char *fileName = NULL;
185 #if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400
186 const wchar_t *fileNameWide = NULL;
187 if (!parameters.
GetValue(Name::OutputFileNameWide(), fileNameWide))
189 if (!parameters.
GetValue(Name::OutputFileName(), fileName))
191 parameters.
GetValue(Name::OutputStreamPointer(), m_stream);
195 std::ios::openmode binary = parameters.
GetValueWithDefault(Name::OutputBinaryMode(),
true) ? std::ios::binary : std::ios::openmode(0);
196 m_file.reset(
new std::ofstream);
197 #ifdef CRYPTOPP_UNIX_AVAILABLE
198 std::string narrowed;
200 fileName = (narrowed =
StringNarrow(fileNameWide)).c_str();
201 #elif (CRYPTOPP_MSC_VERSION >= 1400)
204 m_file->open(fileNameWide, std::ios::out | std::ios::trunc | binary);
211 m_file->open(fileName, std::ios::out | std::ios::trunc | binary);
215 m_stream = m_file.get();
220 CRYPTOPP_UNUSED(hardFlush), CRYPTOPP_UNUSED(blocking);
222 throw Err(
"FileSink: output stream not opened");
225 if (!m_stream->good())
231 size_t FileSink::Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking)
233 CRYPTOPP_UNUSED(blocking);
235 throw Err(
"FileSink: output stream not opened");
239 std::streamsize size;
241 size = ((std::numeric_limits<std::streamsize>::max)());
242 m_stream->write((
const char *)inString, size);
244 length -= (size_t)size;
250 if (!m_stream->good())