fs.prepend
fs.prepend
功能
把内容写到文件开头。
语法
fs(path).prepend(content)
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| content | Any | 否 | '' | 要前置写入的内容;数组和对象会写入 JSON 字符串。 |
返回值
| 类型 | 说明 |
|---|---|
| Int | 返回新文件内容的总字节数。 |
示例
file = fs('docs-prepend.txt') file.write('Lang') result = file.prepend('BT ') // 输出:7 print result
注意事项
- 文件存在时会先读取旧内容再整体写回。