# undefined FileSystemManager.ftruncateSync(Object object)

Start from base library version 2.16.1. Please remaining backward compatible.

with Promise style call: Not supported

Mini Program plugin: Support, need to Mini Program base library version no less than 2.19.2

Truncate file contents

# parameter

# Object object

attribute type Default values Required Introductions
fd string yes File descriptor. fd adopt FileSystemManager.open or FileSystemManager.openSync Interface acquisition
length number yes Truncate position, default 0. if length Is less than the file length in bytes, only the first length Four bytes will remain in the file and the rest will be deletedif length Is greater than the file length, it will be expanded, and the extension will be filled with empty bytes0')

# Return value

# undefined

# error

Error code Error message Introductions
bad file descriptor Invalid file descriptor
fail permission denied Specified fd No write permissions
fail the maximum size of the file storage limit is exceeded Insufficient storage space
fail sdcard not mounted android sdcard Mount failure

# sample code

const fs = wx.getFileSystemManager()
const fd = fs.openSync({
  filePath: `${wx.env.USER_DATA_PATH}/hello.txt`, 
  flag: 'a+'
})
fs.ftruncateSync({
  fd: fd,
  length: 10 // Truncate the file from the 10th byte
})