FileSource

From Crypto++ Wiki

Jump to: navigation, search

FileSource.png

In the pipelining paradigm, a File Source serves as an origin of data.

[edit] Examples

The following example demonstrates creation of a FileSource.

FileSource file( filename );

The following example demonstrates reading a file, and placing the contents of the file in a string. This is known as Filter Chaining.

string s;
FileSource file( filename, new StringSink( s ) );

cout << s << endl;

The following example performs the same operation as above, but without the variable file.

string s;
FileSource( filename, new StringSink( s ) );

cout << s << endl;

A slightly more complicated example of pipelining is below. Before the FileSource is placed in the string, it is HexEncoded.

string s;
FileSource( filename, new HexEncoder( new StringSink( s ) ) );

cout << s << endl;

Note that the HexEncoder and StringSink created with new do not require explicit destruction - the FileSource will call delete on the HexEncoder, which in turns calls delete on the StringSink when it (the FileSource is destroyed.

Personal tools