64 if (
fp == NULL || lz4fRead == NULL) {
65 return -LZ4F_ERROR_GENERIC;
69 if (*lz4fRead == NULL) {
70 return -LZ4F_ERROR_allocation_failed;
80 consumedSize = fread(buf, 1,
sizeof(buf), (*lz4fRead)->fp);
81 if (consumedSize !=
sizeof(buf)) {
83 return -LZ4F_ERROR_GENERIC;
96 (*lz4fRead)->srcBufMaxSize = 64 * 1024;
99 (*lz4fRead)->srcBufMaxSize = 256 * 1024;
102 (*lz4fRead)->srcBufMaxSize = 1 * 1024 * 1024;
105 (*lz4fRead)->srcBufMaxSize = 4 * 1024 * 1024;
110 return -LZ4F_ERROR_maxBlockSize_invalid;
113 (*lz4fRead)->srcBuf = (
LZ4_byte*)malloc((*lz4fRead)->srcBufMaxSize);
114 if ((*lz4fRead)->srcBuf == NULL) {
117 return -LZ4F_ERROR_allocation_failed;
120 (*lz4fRead)->srcBufSize =
sizeof(buf) - consumedSize;
121 memcpy((*lz4fRead)->srcBuf, buf + consumedSize, (*lz4fRead)->srcBufSize);
131 if (lz4fRead == NULL || buf == NULL)
132 return -LZ4F_ERROR_GENERIC;
150 return -LZ4F_ERROR_GENERIC;
173 if (lz4fRead == NULL)
174 return -LZ4F_ERROR_GENERIC;
178 return LZ4F_OK_NoError;
186 if (
fp == NULL || lz4fWrite == NULL)
187 return -LZ4F_ERROR_GENERIC;
190 if (*lz4fWrite == NULL) {
191 return -LZ4F_ERROR_allocation_failed;
193 if (prefsPtr != NULL) {
197 (*lz4fWrite)->maxWriteSize = 64 * 1024;
200 (*lz4fWrite)->maxWriteSize = 256 * 1024;
203 (*lz4fWrite)->maxWriteSize = 1 * 1024 * 1024;
206 (*lz4fWrite)->maxWriteSize = 4 * 1024 * 1024;
210 return -LZ4F_ERROR_maxBlockSize_invalid;
213 (*lz4fWrite)->maxWriteSize = 64 * 1024;
216 (*lz4fWrite)->dstBufMaxSize =
LZ4F_compressBound((*lz4fWrite)->maxWriteSize, prefsPtr);
217 (*lz4fWrite)->dstBuf = (
LZ4_byte*)malloc((*lz4fWrite)->dstBufMaxSize);
218 if ((*lz4fWrite)->dstBuf == NULL) {
220 return -LZ4F_ERROR_allocation_failed;
225 free((*lz4fWrite)->dstBuf);
233 free((*lz4fWrite)->dstBuf);
238 if (
ret != fwrite(buf, 1,
ret,
fp)) {
240 free((*lz4fWrite)->dstBuf);
242 return -LZ4F_ERROR_GENERIC;
245 (*lz4fWrite)->fp =
fp;
246 (*lz4fWrite)->errCode = LZ4F_OK_NoError;
247 return LZ4F_OK_NoError;
253 size_t remain =
size;
257 if (lz4fWrite == NULL || buf == NULL)
258 return -LZ4F_ERROR_GENERIC;
275 lz4fWrite->
errCode = -LZ4F_ERROR_GENERIC;
276 return -LZ4F_ERROR_GENERIC;
290 if (lz4fWrite == NULL)
291 return -LZ4F_ERROR_GENERIC;
293 if (lz4fWrite->
errCode == LZ4F_OK_NoError) {
302 ret = -LZ4F_ERROR_GENERIC;