Is there a chance to get this methods (or any better versions of them)
added to Metacello?
>>extractZip: fileRef in: dst
" If fileRef is a ZIP archive, uncompress its contents in dst and
delete it "
| zipArchive |
(fileRef fullName endsWith: '.zip')
ifFalse: [ ^ self ].
zipArchive := ZipArchive new.
[ zipArchive
readFrom: fileRef fullName;
extractAllTo: dst ]
ensure: [ zipArchive close ].
fileRef delete
>>extractGZip: fileRef in: dst
" If fileRef is a ZIP archive, uncompress its contents in dst and
delete it "
| unzipped |
(fileRef fullName endsWith: '.gz')
ifFalse: [ ^ self ].
unzipped := GZipReadStream unzip: fileRef basename to: dst.
(Smalltalk hasClassNamed: #OSProcess)
ifTrue: [
(Smalltalk at: #OSProcess) thisOSProcess waitForCommandOutput:
'tar xvf ' , unzipped asFileReference fullName.
fileRef delete.
unzipped asFileReference delete ]
>>uncompress: fileRef
" Private - Uncompress fileRef to the current working directory "
| dst |
dst := FileSystem workingDirectory.
self extractZip: fileRef in: dst.
self extractGZip: fileRef in: dst.
>>downloadResourcesFrom: urlString
" Private - Download files from urlString "
^ [ ZnEasy get: urlString ]
on: ZnEntityTooLarge
do: [ : ex | ex resume ].
I use them to download external resources for my projects as follows:
First I add a #preLoadDoIt: send in my baseline:
spec for: #'common' do: [
spec blessing: #'baseline'.
spec preLoadDoIt: #preLoad.
....
>>preLoad
| url fileRef response |
self logCr: '====== Downloading my resource files...'.
url := self platformFilesUrl asZnUrl.
fileRef := FileSystem disk workingDirectory / url pathSegments last.
(response := self downloadResourcesFrom: url) isSuccess
ifTrue: [
self logCr: '====== Writing resource file...'.
fileRef writeStreamDo: [ : stream | stream nextPutAll: response
contents ] ]
ifFalse: [ self error: 'Cannot download data files' ].
self logCr: '====== Uncompressing files...'.
self uncompress: fileRef.
Hernán