WARNING: The [sjs-3] engine was deprecated, use [sjs-4] instead.

File.prototype.copy()

Make a deep copy of a file.

Syntax

file.copy(placement uint32, target File) File file.copy(placement uint32, target File, name string) File file.copy(placement uint32, target File, name string, bucketId uint8) File

Parameters

placement uint32

Where to place the new file relative the the target. One of [os.BEFORE, os.AFTER, os.PREPEND, os.APPEND]. Additionally, you can use one or more of [os.FORCE, os.RENAME, os.TYPESAFE, os.TYPESAFE_IF_POSSIBLE]. See file placement for more details.

target File

Place the copied file relative to this one.

name string

File’s name. It is an error to use special characters like spaces. Providing an empty string or omitting the name argument defaults to using the name of the source file.

bucketId uint8

Which bucket to place the file in. Unused for placement directions os.BEFORE and os.AFTER. Also, for directions os.APPEND and os.PREPEND, you can make the system select a bucket when using the os.TYPESAFE or os.TYPESAFE_IF_POSSIBLE flags.

Description

Make a deep copy of referenced file and place it in the filesystem relative to the target file. The returned file does not need to be explicitly stored, every file operation is automatically commited to disk once the transaction successfully exits.

Examples

Basic example, make a copy after self.

Basic example, make a copy after self, provide file name.

Basic example, make a copy in another bucket.

Placement os.PREPEND.

Placement os.APPEND.

Placement os.BEFORE.

Placement os.AFTER.

Copying a file with the TYPESAFE flag will respect .Accept rules.

Copying a file with the TYPESAFE flag will respect .Accept rules. If the .Accept rules deny placement, the operation will fail.

It is invalid to use spaces or special chars in the name.