npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tcbfs

v0.2.1

Published

A comprehensive module for managing file operations with Tencent CloudBase, including upload, download, delete, compression, and decompression.

Downloads

11

Readme

tcbfs

tcbfs 是一个用于管理腾讯云 CloudBase 文件操作的模块,支持文件的上传、下载、删除、压缩和解压缩操作。

功能

  • 上传文件:支持上传单个文件和批量文件到云存储。
  • 下载文件:支持从云存储中下载单个文件和批量文件。
  • 删除文件:支持删除单个文件和批量文件。
  • 获取临时访问 URL:获取文件的临时访问 URL。
  • 组织文件路径:为压缩和解压缩操作做准备。
  • 压缩文件:支持压缩文件和目录。
  • 解压文件:支持解压缩文件。

安装

要安装 tcbfs,可以使用以下命令:

npm install tcbfs

使用

  • 为了实现方便直观的云存储操作,云存储的根目录当作 / 目录进行处理
  • 同时为了避免混淆,当前层级路径应使用 ./ 表示
  • 所有函数都是异步函数,应使用 async/await 调用

上传文件

上传单个文件到云存储:

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));

上传多个文件到云存储:

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));

下载文件

下载单个文件:

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));

下载多个文件:

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));

删除文件

删除单个文件:

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));

删除多个文件:

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));

获取临时访问 URL

获取单个文件的临时访问 URL:

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:

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));

压缩文件

压缩文件或目录:

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));

解压文件

解压文件:

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 说明

upload(cloudPath, fileContent)

上传文件到云存储。

  • 参数

    • cloudPath (String): 文件在云存储中的路径。
    • fileContent (Buffer | String): 文件内容,支持 Buffer 和本地文件路径。
  • 返回

    • Promise<String>: 返回文件的唯一标识 ID。

multiupload(fileList)

批量上传文件到云存储。

  • 参数

    • fileList (Array): 文件列表,每个对象包含 cloudPathfileContent
  • 返回

    • Promise<Array<String>>: 返回上传成功的文件 IDs 列表。

download(file)

下载单个文件。

  • 参数

    • file (String): 文件在云存储中的路径。
  • 返回

    • Promise<Buffer>: 返回文件内容的 Buffer。

multidownload(fileList)

批量下载文件。

  • 参数

    • fileList (Array): 文件路径列表。
  • 返回

    • Promise<Array<Buffer>>: 返回文件内容的 Buffer 列表。

remove(file)

删除单个文件。

  • 参数

    • file (String): 文件在云存储中的路径。
  • 返回

    • Promise<void>: 返回删除操作的结果。

multiremove(fileList)

批量删除文件。

  • 参数

    • fileList (Array): 文件路径列表。
  • 返回

    • Promise<void>: 返回删除操作的结果。

getTempFileURL(file)

获取单个文件的临时访问 URL。

  • 参数

    • file (String): 文件在云存储中的路径。
  • 返回

    • Promise<String>: 返回文件的临时访问 URL。

getTempFileURLs(fileList)

获取多个文件的临时访问 URLs。

  • 参数

    • fileList (Array): 文件路径列表。
  • 返回

    • Promise<Array<String>>: 返回文件的临时访问 URLs 列表。

compressFiles({ fileList, outputPath })

压缩文件或目录。

  • 参数

    • fileList (Array): 文件列表,每个对象包含 fileNamefileContent
    • outputPath (String): 输出压缩文件的路径。
  • 返回

    • Promise<void>: 返回压缩操作的结果。

decompressFile({ inputPath, outputDir })

解压文件。

  • 参数

    • inputPath (String): 输入的压缩文件路径。
    • outputDir (String): 解压到的输出目录路径。
  • 返回

    • Promise<void>: 返回解压操作的结果。

贡献

欢迎贡献代码!请遵循以下步骤:

  1. Fork 本项目
  2. 创建你的特性分支 (git checkout -b feature/your-feature)
  3. 提交你的修改 (git commit -am 'Add new feature')
  4. 推送到分支 (git push origin feature/your-feature)
  5. 创建一个新的 Pull Request

许可证

该项目采用 ISC 许可证