#include <lzexpand.h> |
int LZRead(hf, lpvBuf, cb) | |||||
HFILE hf; | /* handle of the file, */ | ||||
void FAR* lpvBuf; | /* address of buffer for file data | */ | |||
int cb; | /* number of bytes to read | */ |
The LZRead function reads into a buffer bytes from a file.
hf
Identifies the source file.
lpvBuf
Points to a buffer that is to receive the bytes read from the file.
cb
Specifies the maximum number of bytes to be read.
The return value is the actual number of bytes read if the function is successful. Otherwise, it is an error value that is less than zero and may be any of the following:
Value | Meaning |
LZERROR_BADINHANDLE | The handle identifying the source file was invalid. |
LZERROR_BADVALUE | The cb parameter specified a negative value. |
LZERROR_GLOBLOCK | The handle identifying required initialization data is invalid. |
LZERROR_READ | The format of the source file was invalid. |
LZERROR_UNKNOWNALG | The file was compressed with an unrecognized compression algorithm. |
If the file is not compressed, LZRead calls the _lread function, which performs the read operation.
If the file is compressed, LZRead emulates _lread on an expanded image of the file and copies the bytes of data into the buffer to which lpvBuf points.
If the source file was compressed by Microsoft File Compression Utility (COMPRESS.EXE), the LZOpenFile, LZSeek, and LZRead functions can be called instead of the OpenFile, _llseek, and _lread functions.
The following example uses LZRead to copy and decompress a compressed file:
char szSrc[] = {"readme.cmp"};
char szFileName[128];
OFSTRUCT ofStrSrc;
OFSTRUCT ofStrDest;
HFILE hfSrcFile, hfDstFile, hfCompFile;
int cbRead;
BYTE abBuf[512];
/* Open the compressed source file. */
hfSrcFile = OpenFile(szSrc, &ofStrSrc, OF_READ);
/*
* Initialize internal data structures for the decompression
* operation.
*/
hfCompFile = LZInit(hfSrcFile);
/* Retrieve the original name for the compressed file. */
GetExpandedName(szSrc, szFileName);
/* Create the destination file using the original name. */
hfDstFile = LZOpenFile(szFileName, &ofStrDest, OF_CREATE);
/* Copy the compressed source file to the destination file. */
do {
if ((cbRead = LZRead(hfCompFile, abBuf, sizeof(abBuf))) > 0)
_lwrite(hfDstFile, abBuf, cbRead);
else {
.
. /* handle error condition */
.
}
} while (cbRead == sizeof(abBuf));
/* Close the files. */
LZClose(hfSrcFile);
LZClose(hfDstFile);
_llseek, _lread, LZOpenFile, LZRead, LZSeek