Custom I/O for Stream Cache
Stream Cache servers do their I/O over a pair of abstract classes. This allows a user to write their own classes that inherit from these abstract base classes to customize I/O. This can be useful if you want to, for example, do your SC I/O over websockets or another protocol, or lay your files out in a way that would make them normally unreadable by the default SC filesystem methods.
In order to specify an AbstractFilesystem you only need to provide a pointer to it in your SC::Server::StreamCacheServer::Config
.
When opening SCZ files for viewing, they will need to be extracted. To do this, they are unzipped and their contents written to the workspace, which is specified as part of SC::Server::StreamCacheServer::Config
.
The abstract classes
There are two classes that need to be implemented: AbstractFilesystem
and AbstractFile
. Both can be found in sc_io.h.
AbstractFilesystem
This provides libsc with the means to navigate the filesystem and query files. The following methods will need to be implemented:
Method |
Description |
---|---|
|
Creates a new object inherited from |
|
Creates a new |
|
Cleans a path. For example, removes |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Fills |
|
Removes everything in the directory at path. Returns the number of items removed. |
|
Removes the file at |
|
Renames the file at |
|
Creates a directory at path. Returns true if successful. |
|
Creates a directory at path. Creating any other directories needed ahead of it. Returns true if successful. |
AbstractFile
This provides libsc
with the means to interact with files, including reading and writing data. The following methods will need to be implemented:
Method |
Description |
---|---|
|
Acquires the resource. At the very least this must update the |
|
Releases the resource (closes the file). |
|
Moves the read/write offset to somewhere within the file. Can be offset from the beginning, current position or end depending on the |
|
Truncates data after the current offset. Returns true if successful. |
|
Gets the size of the file. |
|
Reads |
|
Writes |
|
Flush the cache, if any. Returns true if successful. |
Node SC server REST I/O
The node server included with the HOOPS Communicator package is capable of doing I/O over REST for use cases where you might want to read SC data directly over the network. To make use of this, you’d write a server that exposes a REST API that the SC server would communicate with to query and retrieve SC data.
Usage with the Node server
To use REST with the node server included with the package, a few things will need to be set up.
In your config, you’ll need to set the restFileserver
parameter to the address of your REST file server.
The paths that will be requested from your REST server will be dependent on the modelDirs
parameter in your config. For example, if your SC server is on Windows, your modelDirs
parameter is set to ["C:\\models"]
and when you request myModel
, you can expect to see queries about C:\\models\\myModel
.
The API
All endpoints should send JSON responses except read
which sends an octet-stream.
Endpoint |
Parameters |
Description |
Returns |
---|---|---|---|
|
offset, size |
Reads |
An octet-stream with the requested bytes |
|
None |
Checks if the file or directory at |
{ exists: boolean } |
|
None |
Returns the size of a file |
{ size: u64 } |
|
None |
Checks if |
{ isDir: boolean } |
|
None |
Checks if |
{ isRegularFile: boolean } |
|
None |
Checks if |
{ isSymlinkFile: boolean } |
|
None |
Checks if the file or directory at |
{ isEmpty: boolean } |
|
None |
Gets the children of the directory at |
{ children: string[] } |