'From Squeak3.3alpha of 12 January 2002 [latest update: #4781] on 27 February 2002 at 11:22:37 pm'! "Change Set: zipsInFileList2-nk Date: 23 February 2002 Author: Ned Konz The ability to recognize Zip archives by their contents from the FileList was lost in recent changes. This restores that ability, and removes an unnecessary method. (note: minor tweaks by sw)"! !ArchiveViewer methodsFor: 'initialization' stamp: 'nk 2/5/2002 14:43'! contents self selectedMember ifNil: [^ '']. viewAllContents ifFalse: [^ self selectedMember contentsFrom: 1 to: 500]. ^ self selectedMember contents! ! !ArchiveViewer class methodsFor: 'class initialization' stamp: 'nk 2/23/2002 13:01'! fileReaderServicesForFile: fullName suffix: suffix | services | services _ OrderedCollection new. (suffix asLowercase = 'zip' or: [ZipArchive isZipArchive: fullName]) ifTrue: [services add: self serviceOpenInZipViewer]. services add: self serviceAddToNewZip. ^ services! ! !FileList methodsFor: 'initialization' stamp: 'sw 2/27/2002 22:32'! buttonSelectorsToSuppress "Answer a list of action selectors whose corresponding services we would prefer *not* to have appear in the filelist's button pane; this can be hand-jimmied to suit personal taste." ^ #(removeLineFeeds: addFileToNewZip:)! ! !GZipReadStream class methodsFor: 'class initialization' stamp: 'nk 2/27/2002 10:14'! initialize "GZipReadStream initialize" #( (GZipMagic 16r8B1F) "GZIP magic number" (GZipDeflated 8) "Compression method" (GZipAsciiFlag 16r01) "Contents is ASCII" (GZipContinueFlag 16r02) "Part of a multi-part archive" (GZipExtraField 16r04) "Archive has extra fields" (GZipNameFlag 16r08) "Archive has original file name" (GZipCommentFlag 16r10) "Archive has comment" (GZipEncryptFlag 16r20) "Archive is encrypted" (GZipReservedFlags 16rC0)"Reserved" ) do: [:spec | GZipConstants redefineName: spec first as: spec last export: true]. FileList registerFileReader: self! ! !ZipArchive methodsFor: 'archive operations' stamp: 'nk 2/5/2002 14:25'! readFrom: aStreamOrFileName | stream name eocdPosition | stream _ aStreamOrFileName isStream ifTrue: [name _ aStreamOrFileName name. aStreamOrFileName] ifFalse: [StandardFileStream oldFileNamed: (name _ aStreamOrFileName)]. stream binary. eocdPosition _ self class findEndOfCentralDirectoryFrom: stream. eocdPosition <= 0 ifTrue: [self error: 'can''t find EOCD position']. self readEndOfCentralDirectoryFrom: stream. stream position: eocdPosition - centralDirectorySize. self readMembersFrom: stream named: name! ! !ZipArchive class methodsFor: 'constants' stamp: 'nk 2/5/2002 14:49'! findEndOfCentralDirectoryFrom: stream "Seek in the given stream to the end, then read backwards until we find the signature of the central directory record. Leave the file positioned right before the signature. Answers the file position of the EOCD, or 0 if not found." | data fileLength seekOffset pos maxOffset | stream setToEnd. fileLength _ stream position. "If the file length is less than 18 for the EOCD length plus 4 for the signature, we have a problem" fileLength < 22 ifTrue: [^ self error: 'file is too short']. seekOffset _ 0. pos _ 0. data _ String new: 4100. maxOffset _ 40960 min: fileLength. "limit search range to 40K" [ seekOffset _ (seekOffset + 4096) min: fileLength. stream position: fileLength - seekOffset. data _ stream next: (4100 min: seekOffset) into: data startingAt: 1. pos _ data lastIndexOfPKSignature: EndOfCentralDirectorySignature. pos = 0 and: [seekOffset < maxOffset] ] whileTrue. ^ pos > 0 ifTrue: [ | newPos | stream position: (newPos _ (stream position + pos - seekOffset - 1)). newPos] ifFalse: [0]! ! !ZipArchive class methodsFor: 'file format' stamp: 'sw 2/27/2002 23:22'! isZipArchive: aStreamOrFileName "Answer whether the given filename represents a valid zip file." | stream eocdPosition | stream _ aStreamOrFileName isStream ifTrue: [aStreamOrFileName] ifFalse: [StandardFileStream oldFileNamed: aStreamOrFileName]. stream ifNil: [^ false]. "nil happens sometimes somehow" stream binary. eocdPosition _ self findEndOfCentralDirectoryFrom: stream. stream ~= aStreamOrFileName ifTrue: [stream close]. ^ eocdPosition > 0! ! ZipArchive removeSelector: #findEndOfCentralDirectoryFrom:! GZipReadStream initialize!