[ENH] Resources

Russell Penney russell.penney at tincanct.com
Tue May 25 10:39:22 UTC 2004

Attached are the beginnings of the Resource framework I threatened to do.
It is still in its infancy but I am already finding how useful it is.

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

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.

( 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
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) ])].

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Resources-Main-rop.10.mcz
Type: application/octet-stream
Size: 8835 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040525/054f4290/Resources-Main-rop.10.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: file3.zip
Type: application/x-zip-compressed
Size: 805 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040525/054f4290/file3.bin
-------------- next part --------------
this is line 1
this is line 2
this is line 3
this is line 4
this is line 5
this is line 6
this is line 7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: file2.jpg
Type: image/jpeg
Size: 741 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040525/054f4290/file2.jpg

More information about the Squeak-dev mailing list