File Object
The CBFS File object gives you simplied access to the disk API.
To create a new file object, you an use:
var file = disk.file( "some/path/somefile.txt" );Then you can access any of the api methods documented here. Enjoy!
var file = disk.file( "somefile.txt" )
.create( "some contents" )
.append( "append contents" );
var mimeType = file.mimeType(); // returns 'text/plain'append
Append contents to the end of a file.
/**
* @contents The contents of the file to append
* @metadata Struct of metadata to store with the file
* @throwOnMissing Boolean flag to throw if the file is missing. Otherwise it will be created if missing.
*
* @return File
*
* @throws cbfs.FileNotFoundException
*/
function append(
required contents,
struct metadata = {},
boolean throwOnMissing = false
);checksum
Generate checksum for a file in different hashing algorithms.
chmod
Sets the access attributes of the file on Unix based disks.
copy
Copy a file from one destination to another.
create
Creates a file on the disk.
delete
Delete a file or an array of file paths. If a file does not exist a false will be shown for its return.
exists
Validate if a file exists.
extension
Extract the extension from the file path.
get
Get the contents of a file.
info
Return information about the file. Will contain keys such as lastModified, size, path, name, type, canWrite, canRead, isHidden and more depending on the provider used.
isExecutable
Returns true if the file is executable.
isHidden
Returns true if the file is hidden.
isReadable
Returns true if the file is readable.
isSymbolicLink
Returns true if the file is a symbolic link.
isWritable
Returns true if the file is writable.
lastModified
Retrieve the file's last modified timestamp.
mimeType
Retrieve the file's mime type.
move
Move a file from one destination to another.
prepend
Prepend contents to the beginning of a file. This is a very expensive operation for local disk storage.
setVisibility
Set the storage visibility of a file. Available options are public, private, readonly or a custom data type the implemented driver can interpret.
size
Returns the size of a file (in bytes). The size may differ from the actual size on the file system due to compression, support for sparse files, or other reasons.
stream
Return a Java stream of the file using non-blocking IO classes. The stream will represent every line in the file so you can navigate through it. This method leverages the cbstreams library used accordingly by implementations (https://www.forgebox.io/view/cbstreams)
temporaryURL
Get a temporary URL for the given file.
touch
Create a new empty file if it does not exist.
url
Gets the URL of a file.
visibility
Get the storage visibility of a file. The return format can be a string of public, private, readonly or a custom data type the implemented driver can interpret.
Last updated
Was this helpful?