About Stream Conversion

Source: Internet
Author: User

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;

 

 

 

 

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.