What I am rambling about is the idea of treating files and file type
as a Resource which has a standard api much like morphs, collections,
streams, etc. A Resource is really a façade over classes like
ImageReadWriter, StandardFileStream, ZipArchive, etc.
Resources are created from URIs (or manually but that isn’t done yet).
I have implemented my own URI implementation even though there are
already a few. My reasoning was that I wanted control over the
implementation so I could try a few things without breaking anything
else. The fundamental difference between my implementation and the
existing ones is I break down the path into a collection. Either I
merge my changes into the existing URI implementation or I hoist the
Jolly Roger and take the URI implementation as me booty arrrr (just
practicing for next years "talk like a pirate" day!).
One thing I am not sure about is the use of the method "contents" to
return the decoded object in a Resource. Is that consistent with other
usage of "contents"?
Please take a look. I think this framework has great potential,
especially for people new to squeak or Smalltalk. There are lots more
to do and a lot of concepts I haven't fleshed out yet.
Lets go through the usage of RURIs (Russell's URI or Resource URI :)
Copy the attached test files (file1.txt,file2.jpg,file3.zip) to the
base directory for your image.
Try
( RURI fromString: 'file1.txt' ) asAbsolute
( RURI fromString: 'file1.txt' ) asAbsolute resource contents
( RURI fromString: './file2.jpg' ) asAbsolute resource contents
( RURI fromString: './' ) asAbsolute resource uriCollection
Zip files are just like directories
( RURI fromString: './file3.zip' ) asAbsolute resource uriCollection
Fragments can be used to access files in Zip files
( RURI fromString: './file3.zip#file1.txt' ) asAbsolute resource
contents
Couple of things to make file portability easier.
First is path mappings. Path maps translate absolute path references
to an absolute path. For example a URI "file:///dir1/dir2/" could be
mapped to "file:///Volume1/dir1/dir2/dir3/".
RFileURI addPathMappingFrom: fromCollection to: toCollection
Second is file names are split into file and extension. This allows
file name mapping for different OSs.
"RFileURI addFileMap: block" takes a two argument block and adds it to
the map for the current OS.
The block when called gets passed file and extension and should return
a string for the os specific filename. An example block is the one for
Win32/Unix [:f :e | f,(e ifNotNil: [ '.',e])] or for a simple one for
DOS [:f :e | (f truncateTo: 8),(e ifNotNil: [ '.',(e truncateTo: 3)
])].
what about making zip files
even more like directories:
( RURI fromString: './file3.zip/file1.txt' ) asAbsolute resource
contents
Fragments are meant to be information to be given to the resource
returned by the uri. So it can transform the data before returning it
to the caller. So "file3.zip#file1.txt" is more appropriate and in
line with the http common usage.