Hi Wei Dai,
I notice that you already changed the interface of FileSource/
FileSink a bit to add support for unicode file name by using
"wchar_t". However, i think this is not the best solution because:
- Not all STL platforms implement std::ifstream::open(const wchar_t*)/
std::ofstream::open(const wchar_t*). Dinkumware STL has these, but it
may not be the case of other implementations (GNU libstdc++, Apache
STL, STLPort, etc).
- "wchar_t" is not portable because its size is vary from platform/
compiler to platform/compiler. On Win32, sizeof(wchar_t) is 2 but on
Linux, it is 4. And there are reports that sizeof(wchar_t) may even
return 1 on some systems. Hence, L"\xnnnnnnnn" is ok only if sizeof
(wchar_t) == 4, and L"\xnnnn" does not work on platform/compiler where
sizeof(wchar_t) == 1.
For all these reasons, I'd like to contribute two classes:
- BinaryInputFileStream
- BinaryOutputFileStream
as the replacement for std::ifstream/std::ofstream when working with
FileSource/FileSink.
Some notes:
- BinaryInputFileStream and BinaryOutputFileStream always open files
in BINARY mode, and they only supports Win32 File System which uses
UTF-16, and Posix File System which uses UTF-8.
- File name must be UTF-8 ENCODED. This is because AFAIK, char is the
only portable character type(new C/C++ charater types like char16_t
and char32_t are still available only on paper), and its size is fixed
at 1 which makes UTF-8 the encoding form of choice. Further more, we
can always expect std::ifstream::open()/std::ofstream::open() to
support "char", but it is not the case of "wchar_t" or other character
types.
- Tested compilers and STL platforms:
MSVC-Dinkumware STL
GCC-libstdc++
GCC-STLPort
Build instructions
1. Download the archive http://h1.ripway.com/ancodecpp/binfstrm.zip
.It contains two files:
- binfstrm.h
- binfstrm.cpp
2. Add binfstrm.cpp as a part of CryptoPP compilation.
3. Recompile CryptoPP.
And that's all. No changes in other header or source files are needed.
Sample code (i just skip non important part):
....
CryptoPP::BinaryInputFileStream inputStream("utf8/path/to/file.txt") //
utf8 file name is welcome
CryptoPP::BinaryOutputFileStream outputStream("utf8/path/to/
file.enc") //utf8 file name is welcome
CryptoPP::FileSource(inputStream, true,
new CryptoPP::StreamTransformationFilter(....,
new CryptoPP::FileSink(outputStream)
)
);
....
Regards,
An
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---