MCPcopy Create free account
hub / github.com/Squirrel/Squirrel.Windows / unzReadCurrentFile

Function unzReadCurrentFile

src/Setup/unzip.cpp:3471–3566  ·  view source on GitHub ↗

Read bytes from the current file. buf contain buffer where data must be copied len the size of buf. return the number of byte copied if somes bytes are copied (and also sets *reached_eof) return 0 if the end of file was reached. (and also sets *reached_eof). return <0 with error code if there is an error. (in which case *reached_eof is meaningless) (UNZ_ERRNO for IO error, or zLib error for uncomp

Source from the content-addressed store, hash-verified

3469// return <0 with error code if there is an error. (in which case *reached_eof is meaningless)
3470// (UNZ_ERRNO for IO error, or zLib error for uncompress error)
3471int unzReadCurrentFile (unzFile file, voidp buf, unsigned len, bool *reached_eof)
3472{ int err=UNZ_OK;
3473 uInt iRead = 0;
3474 if (reached_eof!=0) *reached_eof=false;
3475
3476 unz_s *s = (unz_s*)file;
3477 if (s==NULL) return UNZ_PARAMERROR;
3478
3479 file_in_zip_read_info_s* pfile_in_zip_read_info = s->pfile_in_zip_read;
3480 if (pfile_in_zip_read_info==NULL) return UNZ_PARAMERROR;
3481 if ((pfile_in_zip_read_info->read_buffer == NULL)) return UNZ_END_OF_LIST_OF_FILE;
3482 if (len==0) return 0;
3483
3484 pfile_in_zip_read_info->stream.next_out = (Byte*)buf;
3485 pfile_in_zip_read_info->stream.avail_out = (uInt)len;
3486
3487 if (len>pfile_in_zip_read_info->rest_read_uncompressed)
3488 { pfile_in_zip_read_info->stream.avail_out = (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
3489 }
3490
3491 while (pfile_in_zip_read_info->stream.avail_out>0)
3492 { if ((pfile_in_zip_read_info->stream.avail_in==0) && (pfile_in_zip_read_info->rest_read_compressed>0))
3493 { uInt uReadThis = UNZ_BUFSIZE;
3494 if (pfile_in_zip_read_info->rest_read_compressed<uReadThis) uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
3495 if (uReadThis == 0) {if (reached_eof!=0) *reached_eof=true; return UNZ_EOF;}
3496 if (lufseek(pfile_in_zip_read_info->file, pfile_in_zip_read_info->pos_in_zipfile + pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0) return UNZ_ERRNO;
3497 if (lufread(pfile_in_zip_read_info->read_buffer,uReadThis,1,pfile_in_zip_read_info->file)!=1) return UNZ_ERRNO;
3498 pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
3499 pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
3500 pfile_in_zip_read_info->stream.next_in = (Byte*)pfile_in_zip_read_info->read_buffer;
3501 pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
3502 //
3503 if (pfile_in_zip_read_info->encrypted)
3504 { char *buf = (char*)pfile_in_zip_read_info->stream.next_in;
3505 for (unsigned int i=0; i<uReadThis; i++) buf[i]=zdecode(pfile_in_zip_read_info->keys,buf[i]);
3506 }
3507 }
3508
3509 unsigned int uDoEncHead = pfile_in_zip_read_info->encheadleft;
3510 if (uDoEncHead>pfile_in_zip_read_info->stream.avail_in) uDoEncHead=pfile_in_zip_read_info->stream.avail_in;
3511 if (uDoEncHead>0)
3512 { char bufcrc=pfile_in_zip_read_info->stream.next_in[uDoEncHead-1];
3513 pfile_in_zip_read_info->rest_read_uncompressed-=uDoEncHead;
3514 pfile_in_zip_read_info->stream.avail_in -= uDoEncHead;
3515 pfile_in_zip_read_info->stream.next_in += uDoEncHead;
3516 pfile_in_zip_read_info->encheadleft -= uDoEncHead;
3517 if (pfile_in_zip_read_info->encheadleft==0)
3518 { if (bufcrc!=pfile_in_zip_read_info->crcenctest) return UNZ_PASSWORD;
3519 }
3520 }
3521
3522 if (pfile_in_zip_read_info->compression_method==0)
3523 { uInt uDoCopy,i ;
3524 if (pfile_in_zip_read_info->stream.avail_out < pfile_in_zip_read_info->stream.avail_in)
3525 { uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
3526 }
3527 else
3528 { uDoCopy = pfile_in_zip_read_info->stream.avail_in ;

Callers 1

UnzipMethod · 0.85

Calls 5

lufseekFunction · 0.85
lufreadFunction · 0.85
zdecodeFunction · 0.85
ucrc32Function · 0.85
inflateFunction · 0.85

Tested by

no test coverage detected