[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

[U8] U8 volumes

The access to file contents in S8 is provided by String methods.
Read more browsing

Uploaded Image: idea.gifOn each platform the mechanism of file i/o can be extended registering "U8 volumes" that are low-level handlers of pathNames and accessors to contents in native files/folders.

U8 tools on Web platform

The defauilt volumes for the web are handlers for
u8:The volume in path will be expanded to access U8 service at profile root. e.g. the expression
'u8:aleReimondo/' fileContents
will return contents of page in the U8 service at http://u8.smalltalking.net/profile/aleReimondo/
swiki:The volume in path will be expanded to access our community swiki server. e.g. the expression
'swiki:U8/.pages' fileContents
will return the index of pages in this swiki

Implementing a volume driver

In this example we implement a file driver registered as volume "code". This driver will map classes as files.
When #fileContents is sent to 'code:ClassName' the returned contents will be the fileOut of the class named ClassName.
When #outputToFile: is sent to a string (code in fileIn format), the receiver wil be filedIn with the class named ClassName as receiver during fileIn.

The implementation sample follows
U8 volumes at: #code put: [:path :key| | cls driver |
	cls := Smalltalk at: path ifAbsent: [].
	driver := PoolDictionary new.
		at: #fileWrite:mode: put: [:aString :mode| aString stream fileInto: cls ];
		at: #contentsDo:timeout: put: [:aBlock :timeout| aBlock evaluateWith: cls fileOut ];
		at: #asyncContentsDo:timeout: put: [:aBlock :timeout| self error: 'Not async i/o implemented' ];

Try this expression to see how it works
'code:Point' fileContents