1. The so-called "stream" refers to a piece of memory or data. You don't have to worry about the specific data of the stream, as long as you know the stream size and position.
The most important thing for stream operations is read and write. The most important methods for such controls are readfromstream and savetostream;
2. decompress the memory stream compression stream and decompress the audio stream encodestream decodestream
The memory stream mainly reads hard disk data and writes hard disk data.
Mstream: tmemorystream;
Mstream: = tmemorystream. Create;
Mstream. loadfromfile ('C: // temp // test.txt /');
Or tstrings savetostream (mstream); write data to the stream
The compressed stream and decompression stream compress and decompress the data. They need to use the memory stream for operations, and they do not have the place to store the data themselves.
VaR
M1, M2: tmemorystream;
Comstream: tcompressionstream;
Sstream: tstringstream;
Begin
M1: = tmemorystream. Create; M2: = tmemorystream. Create;
M1.loadfromfile ('C: // temp // test.txt /');
M2.setsize (Num );
Comstream: = tcompressionstream. Create (cldefault, m2); // The first parameter is the compression ratio, and the second parameter is the received memory stream.
M1.savetostream (comstream); input the stream to be compressed or use comstream. write (buffer, count) count is the number of bytes, and buffer is the compressed buffer. In this way, data is directly compressed into the received memory stream and no longer received by the memory stream.
If it fails, freeandnil (comstream) can be used to release it.
M2.savetofile ('C: // temp // test.zip x/') // Save the compressed file
Comstream. Position: = 0;
Sstream: = tstringstream. Create ('');
Encodestream (comstream, sstream); // encrypt the data;
Result: = sstream. datastring;
Do not forget to release the stream File
Sstream. Free;
Comstream. Free;
M1.free;
M2.free;