Contents

write(contents:to:at:replyHandler:)

Writes contents to the given file item.

Declaration

func write(contents: Data, to item: FSItem, at offset: off_t, replyHandler reply: @escaping  @Sendable (FSWriteFileResult?, (any Error)?) -> Void)
func write(contents: Data, to item: FSItem, at offset: off_t) async throws -> FSWriteFileResult

Parameters

  • contents:

    A buffer containing the data to write to the file.

  • item:

    The item to which to write. FSKit guarantees this item will be of type File.

  • offset:

    The offset in the file from which to start writing.

  • reply:

    A block or closure to indicate success or failure. If writing succeeds, pass an instance of Fswritefileresult containing the number of bytes written, the updated Attributes of the file, and the volume’s updated free space, along with a nil error. If writing fails, pass the relevant error as the second parameter; FSKit ignores the Fswritefileresult instance in this case. For an async Swift implementation, there’s no reply handler; simply return the result instance or throw an error.

Discussion

FSKit expects this routine to allocate space in the file system to extend the file as necessary.

If the volume experiences an out-of-space condition, reply with an error of domain NSPOSIXErrorDomain and code ENOSPC.

See Also

Reading and writing