A resource provides access to a specific data stream based on its Internet URL or IRI address. A resource might be an Acorn program, an image, or an audio or video stream. For example, the address for a 3-D world might be:

http://futureworld.com/world.acn	# An Acorn program

Acorn's '@' operator, used to load resources, implicitly makes use of Resource and baseurl (the address of the referring program). Acorn programs typically use '@' to automatically load their static resource parts using relative addresses:

+World
	scene: @scene	# refers to the value of the resource at http://futureworld.com/scene.acn

Class Methods and Properties

extensions
-> index

Resource.Load uses this Index to map a loaded resource's filename extensions to the Acorn type able to deserialize its byte streams into values. For example, the 'acn' extension maps to the Method type which compiles and runs the Acorn program to obtain its value.

loaders
-> index

The loaders cache is a weak Index that maps a resource's absolute url (a symbol) to the resource's loader, if the resource is currently being loaded. The loader stores load status properties like "resource" and "value".

New
(url, baseurl) -> resource

This creates a resource instance which points to a resource located at a specific address. It performs no i/o. If url does not specify any path, 'world.acn' is assumed. If the resource name has no extension, '.acn' is assumed.

If baseurl is not specified, url must be an absolute URL. If the url has a domain (authority) but is missing the scheme, 'http://' is assumed. Otherwise, 'file://' is assumed (which allows use of '.' or '..' off the current working directory).

If baseurl is specified, url may be a relative url (without scheme and domain). The relative url may begin with '/' to reset the full path. The relative url may make use of '.' or '..' for relative folder navigation.

schemes
-> index

Resource.Load uses this Index to determine which Acorn type to use to Get the resource's stream based on the scheme specified by the resource. For example, the 'http' scheme maps to Http and 'file' to File.

values
-> index

The values cache is an weak Index that maps a resource's absolute url (a symbol) to the value of the resource, if it has already been loaded. The values cache ensures that a resource is not loaded more than once.

Instance Methods and Properties

fragment
-> sym

Return a symbol containing the resource's fragment (the part of the resource's URL that followed the '#' pound sign).

Load
(success, failure)->

If not already loaded, this gets the resource's data stream (using its scheme) and then decodes it (based on its extension). This may be done asynchronously. When the resource is loaded, the success method is called, passing the resource's value as a property. If the resource cannot be loaded, the failure method is called, passing the error reason.

url
-> sym

Return a symbol containing the absolute url for the resource.