SilkPerformer provides a very handy function that allows one to read in an entire file into a single variable. However, it works only if the file is text. When GetFileContent() encounters a null byte (0x00), it truncates the rest of the file.
I wanted to use this function to uncompress a gzipped file using ZipUncompressGzip() or ZipUncompressGzip2(). I wasn't able to do so; hence, I used FOpen(), FRead(), and FClose() to retrieve the file content into a string variable. Then I was able to use ZipUncompressGzip2() to get the job done. Yes, it worked!
- FOpen(hZipFile, sSoapFile, OPT_FILE_ACCESS_READ);
- FRead(hZipFile, sTemp, 10000); // should be large enough
- FClose(hZipFile);
- ZipUncompressGzip2(sTemp, sSoapMsg);
If you wish to read in a larger file, you would have to modify the code around FRead() such that you can read in a loop until the entire content is read in. Or use FSizeGet() to get the size of the file and call FRead() appropriately. Here's the revised version:
- FOpen(hZipFile, sSoapFile, OPT_FILE_ACCESS_READ);
- FSizeGet(hZipFile, nLen); // get the file size
- FRead(hZipFile, sTemp, nLen); // read in the whole thing
- FClose(hZipFile); // don't forget to close it
- ZipUncompressGzip2(sTemp, sSoapMsg); // now uncompress
No comments:
Post a Comment