Click to See Complete Forum and Search --> : manipulation of files


khaldoun KASSEM
June 17th, 2002, 10:38 AM
HI to all
I want to open a encrypted file from disk, decrypt it, and use its contents, without saving it to the disk (i mean the decrypted file).
I do the Encryption and the decryption the problem is how can I use it without saving it to the disk??

I can resume the problem: I want to create a file use it but I don't want to save it??
can any one help?
thank you

khaldoun

Elrond
June 17th, 2002, 10:46 AM
I can resume the problem: I want to create a file use it but I don't want to save it??

The beginning is not clear. Do you want to open or to create a file?

Why speaking of a file if it does not exist at all on the disk? The, all you need is a data structure to hold you data. It might be as simple as a simple buffer, or more elaborated structures, arrays, ...

If you want to open a file from the disk but not save it. It is as simple: do not write in it, just read from it, and work on the data you read from it.

Then you can apply you encryption and decryption functions on your buffer or data structure.

khaldoun KASSEM
June 17th, 2002, 10:51 AM
Thank you

my problem is that I use a decryption function who create a file to save the decrypted data to it.
and I use this file to construct an Image.

I want to bypass this procedure and directly create my image from the decrypted data.

thank you

Elrond
June 17th, 2002, 11:21 AM
I suppose that your decoding function reads one fragment of your file decode it and then write it to another file.

Instead of writing it to another file, you could write it to a buffer. When the decoding is complete, the buffer then contains your image.

Philip Nicoletti
June 17th, 2002, 01:30 PM
Maybe the stringstream class will help. It is similar
to what Elrond suggested, in that you use a buffer,
but you can also use various i/o functions to read/write
to the buffer. (it combines string and streams). Here
is a small sample :


#include <iostream>
#include <string>
#include <sstream>

int main()
{
std::stringstream ss(std::ios::binary|std::ios::in|std::ios::out);

ss.put('a');
ss.put('b');
ss.put('c');
ss.put('d');


ss.seekg(0);
char c;
while (ss.get(c))
{
std::cout << c;
}
std::cout << std::endl;

std::cout << ss.str() << std::endl; // ss.str() is std::string
std::cout << ss.str().c_str() << std::endl; // ss.str().c_str() is C style string (read only)

return 0;
}

khaldoun KASSEM
June 18th, 2002, 02:42 AM
Thank you for your help

the problem is that I construct my Image using the file name.
I use visual C++ and the class CImage can be constructed using a file name or a IStream class. and the IStream class isn't like a normal buffer and I don' t know how to use it.

so I want to use a file name??

if I create the file, use it, and then delete it in the same function is there any possiblity that any one using my function has access to the file??


thank you

khaldoun