createFile(name:in:attributes:packer:replyHandler:)
Creates a new file item and map its disk space.
Declaration
func createFile(name: FSFileName, in directory: FSItem, attributes: FSItem.SetAttributesRequest, packer: FSExtentPacker, replyHandler reply: @escaping @Sendable (FSItem?, FSFileName?, (any Error)?) -> Void)func createFile(name: FSFileName, in directory: FSItem, attributes: FSItem.SetAttributesRequest, packer: FSExtentPacker) async throws -> (FSItem, FSFileName)Parameters
- name:
The new file’s name.
- directory:
The directory in which to create the file.
- attributes:
Attributes to apply to the new file.
- packer:
An extent packer you use to pack the file’s allocated disk space.
- reply:
A block or closure to indicate success or failure. If creation succeeds, pass the newly created Fsitem and its Fsfilename, along with a
nilerror. If creation fails, pass the relevant error as the third parameter; FSKit ignores any Fsitem or Fsfilename in this case. For anasyncSwift implementation, there’s no reply handler; instead, return a tuple of the Fsitem and its Fsfilename or throw an error.
Discussion
This method allows the module to opportunistically supply extents, avoiding future calls to blockmapFile(_:offset:length:flags:operationID:packer:replyHandler:). Only perform this technique opportunistically. In particular, don’t perform additional I/O to fetch extent data.
Packing extents in this method requires that attributes defines a size greater than 0.
An implementation that doesn’t supply the extents can ignore the packer and call the corresponding method in the FSVolume.Operations protocol, createItem(named:type:inDirectory:attributes:replyHandler:).