File header processing... [modified]
-
Name Size Value Desciption HEADER 4 bytes 0x04036b2e Mark this file as readable FILE_LEN 4 bytes Int32 Mark the length of FILE block FILE runtime byte[] The file's original name HASH 16 bytes byte[] Hash code of the data(header excluded)
This is a simple header of a compressed file I'm developing. Each time a file is required to be processed, the program will firstly check the header. If passed, compress the file and add header to it. The problem is, I have to firstly read the source file and create the output file, and then compress it by using a third party method(the method will automatically close the input and output stream X| ), then open the output file again, read it out to a buffer, write the header, and finally write the data in the buffer to the output file. It's very inefficient:~. Is there any more efficient way to do this? Thanks in advance...modified on Sunday, May 11, 2008 4:52 AM
Does the method supplied for compression offer the chance to compress it in memory - ie pass it a stream that points to memory? http://msdn.microsoft.com/en-us/library/336wast5.aspx. If so you can use a StringReader/Writer if you wanted to work with strings or any other type of stream reader writer that takes your fancy. This should be faster than writing to disk then re-writing to disk with a header.
At university studying Software Engineering - if i say this line to girls i find they won't talk to me Dan
-
Does the method supplied for compression offer the chance to compress it in memory - ie pass it a stream that points to memory? http://msdn.microsoft.com/en-us/library/336wast5.aspx. If so you can use a StringReader/Writer if you wanted to work with strings or any other type of stream reader writer that takes your fancy. This should be faster than writing to disk then re-writing to disk with a header.
At university studying Software Engineering - if i say this line to girls i find they won't talk to me Dan
-
Yes. It's defined as this:
public void Compress(Stream source, Stream target)
But all the stream I passed to it will be closed. If I use memory stream, I won't be able to retrieve the compressed data.If the stream points to a string then can you not use the string once the stream is closed and compressed. Then add the header added then write it to a file?
At university studying Software Engineering - if i say this line to girls i find they won't talk to me Dan
-
If the stream points to a string then can you not use the string once the stream is closed and compressed. Then add the header added then write it to a file?
At university studying Software Engineering - if i say this line to girls i find they won't talk to me Dan
-
If the header has been generated before compressing, before pass the target stream into the compress method you can try writing the header into the target stream and set the stream's position at the end. My english is very pool, i help i have said clearly.
-
If the header has been generated before compressing, before pass the target stream into the compress method you can try writing the header into the target stream and set the stream's position at the end. My english is very pool, i help i have said clearly.
-
Your hash code is fixed in 16 bytes. Firstly you can wirte 16 empty bytes into to stream before compressing. After you get the HASH, seek the stream'position at the first byte of 16 bytes and write hash code into it.
-
My mean is you can write empty bytes into target stream before compressing, not source stream.