unzip: fullFileName to: pathString
"Unzip the contents of the file specified by the full path name fullFileName to the location given by pathString." so we would expect to pass a string in the second argument? the unique sender of it in the system unzip: fullFileName "Unzip the contents of a gzipped file specified by its full file name to the current working directory" ^ self unzip: fullFileName to: FileSystem disk workingDirectory but the implementation seems to indicate that fullFileName is should be a string as well as pathString unzip: fullFileName to: pathString "Unzip the contents of the file specified by the full path name fullFileName to the location given by pathString." | zipped buffer unzipped newName | newName := fullFileName copyUpToLast: FileSystem disk extensionDelimiter. pathString asFileReference ensureCreateDirectory. unzipped := FileStream newFileNamed: (pathString asFileReference / newName) fullName. unzipped ifNil: [self error: pathString, ' looks incorrect']. [ unzipped binary. zipped := self on: (FileStream readOnlyFileNamed: fullFileName). buffer := ByteArray new: 50000. [zipped atEnd] whileFalse: [unzipped nextPutAll: (zipped nextInto: buffer)]] ensure: [ zipped close. unzipped close]. ^ newName Am I correct to think that the comments are not really good enough? Stef |
I use it a lot to uncompress external resources like this: but it could be used to pass a directory as String I guess.fileRef := .... GZipReadStream unzip: fileRef basename to: FileSystem workingDirectory. 2016-04-19 9:54 GMT-03:00 stepharo <[hidden email]>: unzip: fullFileName to: pathString |
How does unzip:to: access to the file ? It must be in the workingDirectory? 2016-04-19 15:06 GMT+02:00 Hernán Morales Durand <[hidden email]>:
|
Le 19/4/16 15:41, Valentin Ryckewaert a
écrit :
I do not get your question?
Read the code luke.... unzip: fullFileName to: pathString "Unzip the contents of the file specified by the full path name fullFileName to the location given by pathString." | zipped buffer unzipped newName | newName := fullFileName copyUpToLast: FileSystem disk extensionDelimiter. pathString asFileReference ensureCreateDirectory. unzipped := FileStream newFileNamed: (pathString asFileReference / newName) fullName. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unzipped ifNil: [self error: pathString, ' looks incorrect']. [ unzipped binary. zipped := self on: (FileStream readOnlyFileNamed: fullFileName). buffer := ByteArray new: 50000. [zipped atEnd] whileFalse: [unzipped nextPutAll: (zipped nextInto: buffer)]] ensure: [ zipped close. unzipped close]. ^ newName
|
I mean, fileRef basename is myZip.zip and workingDirectory is the place files will go after being unziped but how does we find the file named fileRef basename ? 2016-04-19 15:46 GMT+02:00 stepharo <[hidden email]>:
|
In reply to this post by stepharo
The way I see it is that pathString can be anything that understands asFileReference. This means:
- FileReference - Path - String Doru > On Apr 19, 2016, at 2:54 PM, stepharo <[hidden email]> wrote: > > unzip: fullFileName to: pathString > "Unzip the contents of the file specified by the full path name fullFileName to the location given by pathString." > > so we would expect to pass a string in the second argument? > > the unique sender of it in the system > > unzip: fullFileName > "Unzip the contents of a gzipped file specified by its full file name to the current working directory" > > ^ self unzip: fullFileName to: FileSystem disk workingDirectory > > > but the implementation seems to indicate that fullFileName is should be a string as well as pathString > > unzip: fullFileName to: pathString > "Unzip the contents of the file specified by the full path name fullFileName to the location given by pathString." > > | zipped buffer unzipped newName | > newName := fullFileName copyUpToLast: FileSystem disk extensionDelimiter. > pathString asFileReference ensureCreateDirectory. > unzipped := FileStream newFileNamed: (pathString asFileReference / newName) fullName. > unzipped ifNil: [self error: pathString, ' looks incorrect']. > [ unzipped binary. > zipped := self on: (FileStream readOnlyFileNamed: fullFileName). > buffer := ByteArray new: 50000. > [zipped atEnd] whileFalse: [unzipped nextPutAll: (zipped nextInto: buffer)]] > ensure: [ > zipped close. > unzipped close]. > ^ newName > > Am I correct to think that the comments are not really good enough? > > Stef > > > -- www.tudorgirba.com www.feenk.com "We can create beautiful models in a vacuum. But, to get them effective we have to deal with the inconvenience of reality." |
> On Apr 19, 2016, at 7:10 AM, Tudor Girba <[hidden email]> wrote: > > The way I see it is that pathString can be anything that understands asFileReference. This means: > - FileReference > - Path > - String +1. So a better parameter name would be pathName or path. Parameter names that encode concrete types are sometimes appropriate and hence helpful, sometimes misleading. In this case it's misleading. > Doru > > >> On Apr 19, 2016, at 2:54 PM, stepharo <[hidden email]> wrote: >> >> unzip: fullFileName to: pathString >> "Unzip the contents of the file specified by the full path name fullFileName to the location given by pathString." >> >> so we would expect to pass a string in the second argument? >> >> the unique sender of it in the system >> >> unzip: fullFileName >> "Unzip the contents of a gzipped file specified by its full file name to the current working directory" >> >> ^ self unzip: fullFileName to: FileSystem disk workingDirectory >> >> >> but the implementation seems to indicate that fullFileName is should be a string as well as pathString >> >> unzip: fullFileName to: pathString >> "Unzip the contents of the file specified by the full path name fullFileName to the location given by pathString." >> >> | zipped buffer unzipped newName | >> newName := fullFileName copyUpToLast: FileSystem disk extensionDelimiter. >> pathString asFileReference ensureCreateDirectory. >> unzipped := FileStream newFileNamed: (pathString asFileReference / newName) fullName. >> unzipped ifNil: [self error: pathString, ' looks incorrect']. >> [ unzipped binary. >> zipped := self on: (FileStream readOnlyFileNamed: fullFileName). >> buffer := ByteArray new: 50000. >> [zipped atEnd] whileFalse: [unzipped nextPutAll: (zipped nextInto: buffer)]] >> ensure: [ >> zipped close. >> unzipped close]. >> ^ newName >> >> Am I correct to think that the comments are not really good enough? >> >> Stef > > -- > www.tudorgirba.com > www.feenk.com > > "We can create beautiful models in a vacuum. > But, to get them effective we have to deal with the inconvenience of reality." > > |
In reply to this post by Tudor Girba-2
Le 19/4/16 16:10, Tudor Girba a écrit : > The way I see it is that pathString can be anything that understands asFileReference. This means: > - FileReference > - Path > - String Indeed and we should write it in the comment. > Doru > > >> On Apr 19, 2016, at 2:54 PM, stepharo <[hidden email]> wrote: >> >> unzip: fullFileName to: pathString >> "Unzip the contents of the file specified by the full path name fullFileName to the location given by pathString." >> >> so we would expect to pass a string in the second argument? >> >> the unique sender of it in the system >> >> unzip: fullFileName >> "Unzip the contents of a gzipped file specified by its full file name to the current working directory" >> >> ^ self unzip: fullFileName to: FileSystem disk workingDirectory >> >> >> but the implementation seems to indicate that fullFileName is should be a string as well as pathString >> >> unzip: fullFileName to: pathString >> "Unzip the contents of the file specified by the full path name fullFileName to the location given by pathString." >> >> | zipped buffer unzipped newName | >> newName := fullFileName copyUpToLast: FileSystem disk extensionDelimiter. >> pathString asFileReference ensureCreateDirectory. >> unzipped := FileStream newFileNamed: (pathString asFileReference / newName) fullName. >> unzipped ifNil: [self error: pathString, ' looks incorrect']. >> [ unzipped binary. >> zipped := self on: (FileStream readOnlyFileNamed: fullFileName). >> buffer := ByteArray new: 50000. >> [zipped atEnd] whileFalse: [unzipped nextPutAll: (zipped nextInto: buffer)]] >> ensure: [ >> zipped close. >> unzipped close]. >> ^ newName >> >> Am I correct to think that the comments are not really good enough? >> >> Stef >> >> >> > -- > www.tudorgirba.com > www.feenk.com > > "We can create beautiful models in a vacuum. > But, to get them effective we have to deal with the inconvenience of reality." > > > |
In reply to this post by Valentin Ryckewaert
Le 19/4/16 15:53, Valentin Ryckewaert a
écrit :
'foo.txt' asFileReference -> a fileRef 'foo.txt' asFileReference basename. (FileSystem disk workingDirectory / 'foo.txt') basename this is explained in the File chapter. Can you open a bug entry to improve the comment of the method?
|
Hello, I understood the problem with pathString and I'm ok with your opinion but I would like to come back on the first one "fullfilename" as I understand it, it must be a basename ? When I read the implementation with fullfilename which would be a path '/aPath/foo.zip'. newName := fullFileName copyUpToLast: FileSystem disk extensionDelimiter. newName would be in that case : /aPath/foo' unzipped := FileStream newFileNamed: (pathString asFileReference / newName) fullName. Here the newFileNamed: parameter will be '/aPathDestination/aPath/foo' so it could be something like '/home/home/foo' it's not correct according to me. As I understand it, this message only works if fullFileName is 'foo.zip' and is in the folder which contain Pharo image as we can't specify a path. Valentin 2016-04-19 20:40 GMT+02:00 stepharo <[hidden email]>:
|
Valentin Ryckewaert <[hidden email]> writes:
> Hello, > > I understood the problem with pathString and I'm ok with your opinion but I > would like to come back on the first one "fullfilename" as I understand it, > it must be a basename ? > When I read the implementation with fullfilename which would be a path > '/aPath/foo.zip'. > > newName := fullFileName copyUpToLast: FileSystem disk extensionDelimiter. > newName would be in that case : /aPath/foo' > > unzipped := FileStream newFileNamed: (pathString asFileReference / newName) > fullName. > Here the newFileNamed: parameter will be '/aPathDestination/aPath/foo' so > it could be something like '/home/home/foo' it's not correct according to > me. > > As I understand it, this message only works if fullFileName is 'foo.zip' > and is in the folder which contain Pharo image as we can't specify a path. I agree with Valentin. I have the impression this method can only unzip files in the working directory. That's a bit strange :-). -- Damien Cassou http://damiencassou.seasidehosting.st "Success is the ability to go from one failure to another without losing enthusiasm." --Winston Churchill |
Free forum by Nabble | Edit this page |