Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Exctracted files have not content. #10

Open
kglazov opened this issue Jan 31, 2018 · 2 comments
Open

Some Exctracted files have not content. #10

kglazov opened this issue Jan 31, 2018 · 2 comments

Comments

@kglazov
Copy link

kglazov commented Jan 31, 2018

Hello,
I am using PhpZip 3.1.3.
After extracting files form zip, some text files have no content due to following error.

PhpZip\Stream\ZipInputStream::readEntryContent() - ROOT/vendor/nelexa/zip/src/PhpZip/Stream/ZipInputStream.php, line 443
As a result following error throw an exception with CSC32 not matching error.

Also some of the csv files or xml gzinflate is uncompressing but some csv/xml file returning zero bites.

// get file as stream from GridFS by object id
$stream = $this->GridFS->openDownloadStream($oid);

// Opens a zip-archive from the stream. 
$zipFile = new \PhpZip\ZipFile();
$zipFile->openFromStream($stream)
 	    ->deleteFromRegex('/__MACOSX/')
	    ->deleteFromRegex('/.DS_Store/');


foreach($zipFile->getListFiles() as $entryName) {
     if ($zipFile->hasEntry($entryName) && !$zipFile->isDirectory($entryName)) {
				// get file content form compressed stream
				$contents = $zipFile->getEntryContents($entryName);
				
				// convert contents into resource stream for GridFS storage
				$stream = GuzzleHttp\Psr7\stream_for($contents);
				$resourceStream = StreamWrapper::getResource($stream);
				
				$filename = basename($entryName);
				$response['oids'][] = (string) $this->GridFS->addFile($filename,$resourceStream, $options);
    }
}
@kglazov kglazov closed this as completed Jan 31, 2018
@kglazov kglazov reopened this Jan 31, 2018
@Ne-Lexa
Copy link
Owner

Ne-Lexa commented Feb 1, 2018

If possible, download the problem zip file here.

@kglazov
Copy link
Author

kglazov commented Feb 1, 2018

Hello,

Thank you for quick response. As requested I attached zip file .

I found that there issue with files only when I open zip file as a stream using GridFS. When I open zip form temp directory, such as $zipFile->openFile($file['tmp_name']), every think worked as expected with all type of files.

For example, $zipFile->openFromStream($stream) which obtained form GridFS as a zip stream the library can process only some text, csv, xml, images. In exception for executable, or cpp.

There could be issue with PHP gzinflate function.

files-sample.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants