--- a/FileURI.st Wed Jul 09 14:51:46 2003 +0200
+++ b/FileURI.st Wed Jul 09 14:55:42 2003 +0200
@@ -61,9 +61,9 @@
]
"
- self fromFilename:'/a/b/c' asFilename
- self fromFilename:'//a/b/c' asFilename
- self fromFilename:'a/b/c' asFilename
+ self fromFilename:'/a/b/c' asFilename
+ self fromFilename:'//a/b/c' asFilename
+ self fromFilename:'a/b/c' asFilename
"
! !
@@ -120,6 +120,15 @@
- a collection with a stream on a single file,
- or a collection with streams on a directorie's files, but not recursive"
+ self readStreamsDo:aBlock thenRemove:false.
+!
+
+readStreamsDo:aBlock thenRemove:doRemoveSource
+ "evaluate the block with a Collection of streams as first argument
+ and a dictionary containing attributes as second argument,
+ - a collection with a stream on a single file,
+ - or a collection with streams on a directorie's files, but not recursive"
+
|attributes fn files|
fn := self asFilename.
@@ -141,15 +150,18 @@
attributes at:#fileSize put:(aFile fileSize).
attributes at:#baseName put:baseName.
(self pathSegements includes:baseName) ifTrue:[
- attributes at:#uriInfo put: self printString.
+ attributes at:#uriInfo put:self.
] ifFalse:[
- attributes at:#uriInfo put: ((self copy) addComponent:baseName) printString.
+ attributes at:#uriInfo put:((self copy) addComponent:baseName).
].
stream := aFile readStream.
- aBlock value:stream value:attributes
+ aBlock value:stream value:attributes.
] ensure:[
stream notNil ifTrue:[stream close]
].
+ doRemoveSource == true ifTrue:[
+ aFile remove
+ ].
].
"
@@ -185,10 +197,43 @@
Transcript showCR:(stream isWritable).
].
"
+!
+
+writeStreamDo:aBlock create:doCreate
+ "evaluate a block with the write stream as first argument
+ and a dictionary containing attributes as second argument.
+ The stream is closed after aBlock has been evaluated.
+ Attributes may be the mime type (key #MIME)"
+
+ |stream fileName|
+
+ fileName := self asFilename.
+ [
+ Stream streamErrorSignal handle:[:ex|
+ doCreate ifFalse:[
+ ex reject
+ ].
+ (fileName directory) recursiveMakeDirectory.
+ stream := fileName writeStream.
+ ] do:[
+ stream := fileName writeStream.
+ ].
+ aBlock value:stream value:self class attributes
+ ] ensure:[
+ stream notNil ifTrue:[stream close]
+ ].
+
+ "
+ (URI fromString:'file:/home/tm/tmp')
+ readStreamsDo:[:stream :attributes|
+ Transcript showCR:(attributes at:#MIME).
+ Transcript showCR:(stream isWritable).
+ ].
+ "
! !
!FileURI class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/FileURI.st,v 1.2 2003-06-24 14:10:53 tm Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/FileURI.st,v 1.3 2003-07-09 12:55:42 tm Exp $'
! !