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 🙏

© 2026 – Pkg Stats / Ryan Hefner

fdfs-client-yliyun

v0.5.6

Published

Client for FastDFS

Readme

Nodejs Client for FastDFS

项目fork自 chenboxiang/fdfs-client https://github.com/weilaihui/fdfs_client

原作者停止维护,自己做了一点小更改(如修复无后缀名上传文件出错的bug)

安装

npm install fdfs-client-yliyun

使用(使用方法完全摘自 https://github.com/weilaihui/fdfs_client)

var fdfs = new FdfsClient({
    // tracker servers
    trackers: [
        {
            host: 'tracker.fastdfs.com',
            port: 22122
        }
    ],
    // 默认超时时间10s
    timeout: 10000,
    // 默认后缀
    // 当获取不到文件后缀时使用
    defaultExt: 'txt',
    // charset默认utf8
    charset: 'utf8'
})

以上是一些基本配置,你还可以自定义你的日志输出工具,默认是使用console 例如你要使用debug作为你的日志输出工具,你可以这么做:

var debug = require('debug')('fdfs')
var fdfs = new FdfsClient({
    // tracker servers
    trackers: [
        {
            host: 'tracker.fastdfs.com',
            port: 22122
        }
    ],
    logger: {
        log: debug
    }
})

上传文件

注:以下fileId为group + '/' + filename,以下的所有操作使用的fileId都是一样

通过本地文件名上传

fdfs.upload('test.gif', function(err, fileId) {
    // fileId 为 group + '/' + filename
})

上传Buffer

var fs = require('fs')
// 注意此处的buffer获取方式只为演示功能,实际不会这么去构建buffer
var buffer = fs.readFileSync('test.gif')
fdfs.upload(buffer, function(err, fileId) {
    
})

ReadableStream

var fs = require('fs')
var rs = fs.createReadStream('test.gif')
fdfs.upload(rs, function(err, fileId) {
    
})

其他一些options,作为第2个参数传入

fdfs.upload('test.gif', {
    // 指定文件存储的group,不指定则由tracker server分配
    group: 'group1',
    // file bytes, file参数为ReadableStream时必须指定
    size: 1024,
    // 上传文件的后缀,不指定则获取file参数的后缀,不含(.)
    ext: 'jpg'
    
}, function(err, fileId) {

})

下载文件

下载到本地

fdfs.download(fileId, 'test_download.gif', function(err) {
    
})

下载到WritableStream

var fs = require('fs')
var ws = fs.createWritableStream('test_download.gif')
fdfs.download(fileId, ws, function(err) {

})

下载文件片段

fdfs.download(fileId, {
    target: 'test_download.part',
    offset: 5,
    bytes: 5
}, function(err) {

})

删除文件

fdfs.del(fileId, function(err) {

})

获取文件信息

fdfs.getFileInfo(fileId, function(err, fileInfo) {
    // fileInfo有4个属性
    // {
    //   // 文件大小
    //   size:
    //   // 文件创建的时间戳,单位为秒
    //   timestamp:
    //   // 校验和
    //   crc32:
    //   // 最初上传到的storage server的ip
    //   addr:
    // }
    console.log(fileInfo)
})

文件的Meta Data

设置Meta Data, 我只贴出来文件签名信息吧,flag字段如果不传则默认是O

/**
 * @param fileId
 * @param metaData  {key1: value1, key2: value2}
 * @param flag 'O' for overwrite all old metadata (default)
                'M' for merge, insert when the meta item not exist, otherwise update it
 * @param callback
 */
fdfs.setMetaData(fileId, metaData, flag, callback)

获取Meta Data

fdfs.getMetaData(fileId, function(err, metaData) {
    console.log(metaData)
})

错误处理

当无tracker可用时会触发error事件

fdfs.on('error', function(err) {
    // 在这里处理错误
})

测试

测试时需要用到co,所以需要node版本0.11+。测试前请确保配置好FastDFS的Server地址,为tracker.fastdfs.com:22122,或者修改test/fdfs_test.js中的client配置,然后执行如下命令:

make test

帮助

有任何问题请提交到Github Issue里

授权协议

MIT