- JS API 列表
- 基础
- 网络
- 媒体
- 地图
- 文件
- 开放接口
- 数据缓存
- 地理位置
- 设备
- 画布
- 界面
- 页面导航
- 侧边栏能力
- 行业开放
- AI/AR能力
- 第三方平台
- TTML
- 转发和挂载
- 其它
- 直播能力
FileSystemManager.truncate收藏我的收藏
收藏
我的收藏基础库 2.60.0 开始支持本方法,低版本需做兼容处理,这是一个异步方法。
对文件内容进行截断操作,只有用户目录(ttfile://user)下的文件可以截断。
前提条件 | 无 |
业务背景 | 无 |
使用限制 | 无 |
注意事项 | 无 |
支持沙盒 | 否 |
相关教程 | 无 |
语法
FileSystemManager.truncate(options)
参数说明
options 为 object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
length | number | 0 | 是 | 截断位置,默认 0。如果 length 小于文件长度(字节),则只有前面 length 个字节会保留在文件中,其余内容会被删除;如果 length 大于文件长度,则会对其进行扩展,并且扩展部分将填充空字节('\0') | 2.60.0 |
filePath | string | 是 | 要截断的文件路径, 必须以 ttfile://user 开头 | 2.60.0 | |
success | function | 否 | 接口调用成功的回调函数 | 2.60.0 | |
fail | function | 否 | 接口调用失败的回调函数 | 2.60.0 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 2.60.0 |
回调成功
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | "truncate:ok" | 2.60.0 |
回调失败
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | "truncate:fail" + 详细 错误信息 | 2.60.0 |
错误码
errNo | errMsg | 说明 | 最低支持版本 |
---|---|---|---|
20000 | truncate:fail filePath is required | filePath 参数错误 | 2.60.0 |
21101 | truncate:fail permission denied, truncate %s | 文件路径不可写 | 2.60.0 |
21102 | truncate:fail no such file or directory, truncate %s | filePath 文件不存在 | 2.60.0 |
21103 | truncate:fail user dir saved file size limit exceeded | 超出目录大小限制 | 2.60.0 |
21104 | truncate:fail operation not permitted, truncate %s | filePath 类型不是文件 | 2.60.0 |
扫码体验
请使用字节宿主APP扫码
代码示例
const fs = tt.getFileSystemManager()
fs.truncate({
filePath: `ttfile://user/example.txt`,
length: 10,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
},
})
// 同步接口
try {
fs.truncateSync(`ttfile://user/example.txt`, 10)
} catch (e) {
console.error(e)
}
该文档是否有帮助?
点击纠错