A comprehensive module for managing file operations with Tencent CloudBase, including upload, download, delete, compression, and decompression.
npm install tcbfstcbfs 是一个用于管理腾讯云 CloudBase
tcbfs,可以使用以下命令:
bash
npm install tcbfs
`
使用
- 为了实现方便直观的云存储操作,云存储的根目录当作 / 目录进行处理
- 同时为了避免混淆,当前层级路径应使用 ./ 表示
- 所有函数都是异步函数,应使用 async/await 调用
$3
上传单个文件到云存储:
`javascript
const { upload } = require("tcbfs");
upload("cloud/path/to/file.txt", Buffer.from("File content"))
.then((fileID) => console.log("File uploaded with ID:", fileID))
.catch((err) => console.error("Error uploading file:", err));
`
上传多个文件到云存储:
`javascript
const { multiupload } = require("tcbfs");
const files = [
{
cloudPath: "cloud/path/to/file1.txt",
fileContent: Buffer.from("File 1 content"),
},
{
cloudPath: "cloud/path/to/file2.txt",
fileContent: Buffer.from("File 2 content"),
},
];
multiupload(files)
.then((fileIDs) => console.log("Files uploaded with IDs:", fileIDs))
.catch((err) => console.error("Error uploading files:", err));
`
$3
下载单个文件:
`javascript
const { download } = require("tcbfs");
download("cloud/path/to/file.txt")
.then((fileContent) => console.log("File content:", fileContent))
.catch((err) => console.error("Error downloading file:", err));
`
下载多个文件:
`javascript
const { multidownload } = require("tcbfs");
const fileList = ["cloud/path/to/file1.txt", "cloud/path/to/file2.txt"];
multidownload(fileList)
.then((fileContents) => console.log("File contents:", fileContents))
.catch((err) => console.error("Error downloading files:", err));
`
$3
删除单个文件:
`javascript
const { remove } = require("tcbfs");
remove("cloud/path/to/file.txt")
.then((result) => console.log("File deleted:", result))
.catch((err) => console.error("Error deleting file:", err));
`
删除多个文件:
`javascript
const { multiremove } = require("tcbfs");
const fileList = ["cloud/path/to/file1.txt", "cloud/path/to/file2.txt"];
multiremove(fileList)
.then((result) => console.log("Files deleted:", result))
.catch((err) => console.error("Error deleting files:", err));
`
$3
获取单个文件的临时访问 URL:
`javascript
const { getTempFileURL } = require("tcbfs");
getTempFileURL("cloud/path/to/file.txt")
.then((url) => console.log("Temporary file URL:", url))
.catch((err) => console.error("Error getting temporary file URL:", err));
`
获取多个文件的临时访问 URLs:
`javascript
const { getTempFileURLs } = require("tcbfs");
const fileList = ["cloud/path/to/file1.txt", "cloud/path/to/file2.txt"];
getTempFileURLs(fileList)
.then((urls) => console.log("Temporary file URLs:", urls))
.catch((err) => console.error("Error getting temporary file URLs:", err));
`
$3
压缩文件或目录:
`javascript
const { compressFiles } = require("tcbfs");
compressFiles({
fileList: [
{ fileName: "file1.txt", fileContent: Buffer.from("Content of file 1") },
{ fileName: "file2.txt", fileContent: "local/path/to/file2.txt" },
],
outputPath: "path/to/output.zip",
})
.then(() => console.log("Files compressed successfully"))
.catch((err) => console.error("Error compressing files:", err));
`
$3
解压文件:
`javascript
const { decompressFile } = require("tcbfs");
decompressFile({
inputPath: "path/to/compressed.zip",
outputDir: "path/to/output/dir",
})
.then(() => console.log("Files decompressed successfully"))
.catch((err) => console.error("Error decompressing files:", err));
`
API 说明
$3
上传文件到云存储。
- 参数
- cloudPath (String): 文件在云存储中的路径。
- fileContent (Buffer | String): 文件内容,支持 Buffer 和本地文件路径。
- 返回
- Promise: 返回文件的唯一标识 ID。
$3
批量上传文件到云存储。
- 参数
- fileList (ArraycloudPath 和
fileContent。
- 返回
- Promise: 返回上传成功的文件 IDs 列表。
$3
下载单个文件。
- 参数
- file (String): 文件在云存储中的路径。
- 返回
- Promise: 返回文件内容的 Buffer。
$3
批量下载文件。
- 参数
- fileList (Array): 文件路径列表。
- 返回
- Promise: 返回文件内容的 Buffer 列表。
$3
删除单个文件。
- 参数
- file (String): 文件在云存储中的路径。
- 返回
- Promise: 返回删除操作的结果。
$3
批量删除文件。
- 参数
- fileList (Array): 文件路径列表。
- 返回
- Promise: 返回删除操作的结果。
$3
获取单个文件的临时访问 URL。
- 参数
- file (String): 文件在云存储中的路径。
- 返回
- Promise: 返回文件的临时访问 URL。
$3
获取多个文件的临时访问 URLs。
- 参数
- fileList (Array): 文件路径列表。
- 返回
- Promise: 返回文件的临时访问 URLs 列表。
$3
压缩文件或目录。
- 参数
- fileList (ArrayfileName 和
fileContent。
- outputPath (String): 输出压缩文件的路径。
- 返回
- Promise: 返回压缩操作的结果。
$3
解压文件。
- 参数
- inputPath (String): 输入的压缩文件路径。
- outputDir (String): 解压到的输出目录路径。
- 返回
- Promise: 返回解压操作的结果。
贡献
欢迎贡献代码!请遵循以下步骤:
1. Fork 本项目
2. 创建你的特性分支 (git checkout -b feature/your-feature)
3. 提交你的修改 (git commit -am 'Add new feature')
4. 推送到分支 (git push origin feature/your-feature`)