diff --git a/src/Compression-Tests/ZipArchiveTest.class.st b/src/Compression-Tests/ZipArchiveTest.class.st index 8123f74b214..b9b74fdb500 100644 --- a/src/Compression-Tests/ZipArchiveTest.class.st +++ b/src/Compression-Tests/ZipArchiveTest.class.st @@ -55,6 +55,29 @@ ZipArchiveTest >> testAddNonExistentFile [ self should: [ zip addFile: 'it_would_be_crazy_if_this_file_existed.ext' asFileReference ] raise: FileDoesNotExistException. ] +{ #category : #tests } +ZipArchiveTest >> testArchiveWithThousandFilesShouldWork [ + + "Smoke test showing that we can create zip archives with up to 1000 elements. + This test was created as a regression test. Previous implementations were leaking files and reaching the open file limits from the operating system." + + | dir theZip | + dir := (FileLocator temp / 'testfiles') ensureCreateDirectory. + [ + 1 to: 1000 do: [ :i | + (dir / ('test-' , i asString)) + writeStreamDo: [ :stream | stream nextPutAll: 'file contents' ]; + yourself ]. + + theZip := ZipArchive new. + dir children do: [ :eachFile | theZip addFile: eachFile resolve ]. + theZip writeToFile: FileLocator temp / 'result.zip'. + theZip close. + ] ensure: [ + dir ensureDeleteAll. + (FileLocator temp / 'result.zip') ensureDelete. ] +] + { #category : #tests } ZipArchiveTest >> testCanUnzipFromFileName [ | nestedFileToZip | diff --git a/src/Compression/ZipNewFileMember.class.st b/src/Compression/ZipNewFileMember.class.st index 2b3aca12e98..894a02ccf0e 100644 --- a/src/Compression/ZipNewFileMember.class.st +++ b/src/Compression/ZipNewFileMember.class.st @@ -22,12 +22,18 @@ ZipNewFileMember >> close [ stream ifNotNil:[stream close]. ] +{ #category : #initialization } +ZipNewFileMember >> endRead [ + + super endRead. + self close +] + { #category : #initialization } ZipNewFileMember >> from: aFileReference [ | entry | "Now get the size, attributes, and timestamps, and see if the file exists" - stream := aFileReference binaryReadStream. self localFileName: (externalFileName := aFileReference path pathString). entry := aFileReference entry. compressedSize := uncompressedSize := entry size. @@ -48,16 +54,10 @@ ZipNewFileMember >> initialize [ { #category : #private } ZipNewFileMember >> readRawChunk: n [ + stream ifNil: [ stream := externalFileName asFileReference binaryReadStream ]. ^stream next: n ] -{ #category : #'private-writing' } -ZipNewFileMember >> rewindData [ - super rewindData. - readDataRemaining := stream size. - stream position: 0. -] - { #category : #testing } ZipNewFileMember >> usesFile: aFileReferenceOrFileName [ "Do I require aFileName? That is, do I care if it's clobbered?"