How to obtain a wxUint8 array from a wxFile? Topic is solved
How to obtain a wxUint8 array from a wxFile?
Hi,
I'm looking for a way to have the content of a wxFile in a wxUint8 array.
Is it possible? How?
Thanks
I'm looking for a way to have the content of a wxFile in a wxUint8 array.
Is it possible? How?
Thanks
-
- Part Of The Furniture
- Posts: 1511
- Joined: Sun Jun 19, 2005 11:37 am
- Location: Singapore
- Contact:
Code: Select all
wxFileInputStream strm(wxT("FileName"));
wxUint8* arr = new wxUint8[strm.GetLength()];
strm.Read(arr, strm.GetLength()); //arr has the contents of the entire file now
Joel
-
- Part Of The Furniture
- Posts: 1511
- Joined: Sun Jun 19, 2005 11:37 am
- Location: Singapore
- Contact:
If your code is not state-dependent you can always read 65536 bytes at a time, using Eof to control if you should read more:
Joel
Code: Select all
wxFileInputStream strm(wxT("FileName"));
wxUint8 arr[65536];
while (!strm.Eof())
{
strm.Read(arr, 65536); //arr has the last 65536 bytes (or less, depending of the file pointer's position)
//do stuff with arr. The first strm.LastRead() bytes are valid.
}
-
- Part Of The Furniture
- Posts: 1511
- Joined: Sun Jun 19, 2005 11:37 am
- Location: Singapore
- Contact:
uhm... if it means that the current 65535 bytes does not depend on the 65535 bytes being read before the current one.
Like for example if you are using a CBC or EAX mode encrypted file reading the current block depends on the block before it read so the operation can succeed (like CBC is an XOR with the previous block IIRC), so you cannot jump to the middle of the file and start reading the contents and decrypting the file.
Joel
Like for example if you are using a CBC or EAX mode encrypted file reading the current block depends on the block before it read so the operation can succeed (like CBC is an XOR with the previous block IIRC), so you cannot jump to the middle of the file and start reading the contents and decrypting the file.
Joel
I'd do it like this:
Eran
Code: Select all
wxFileInputStream input( "myfile.txt" );
wxTextInputStream text( input );
wxUint16 i;
std::vector<wxUint16> array;
while( !input.Eof() )
{
text >> i; // read a 16 bit integer.
array.push_back(i);
}
Hi,
I tried to use the piece of code that Joel gave.
Is the n+1 position of the array going to be a '\0'?
(which will stop the encoding so no matter with the reel size)
I tried to use the piece of code that Joel gave.
But a question came to my mind... in the case of the last bytes, less than 65536 bytes are probably going to be read. Then, how will i know exactly how many have been read?lowjoel wrote:Code: Select all
wxFileInputStream strm(wxT("FileName")); wxUint8 arr[65536]; while (!strm.Eof()) { strm.Read(arr, 65536); //arr has the last 65536 bytes (or less, depending of the file pointer's position) //do stuff with arr. The first strm.LastRead() bytes are valid. }
Is the n+1 position of the array going to be a '\0'?
(which will stop the encoding so no matter with the reel size)