
Security News
Google’s OSV Fix Just Added 500+ New Advisories — All Thanks to One Small Policy Change
A data handling bug in OSV.dev caused disputed CVEs to disappear from vulnerability feeds until a recent fix restored over 500 advisories.
FastDFS 是分布式文件存储系统。这个项目是FastDFS的NodeJS客户端,用来与FastDFS Server进行交互,进行文件的相关操作。我测试过的server版本是4.0.6。
npm install fdfs
var FdfsClient = require('fdfs');
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('e:/shou.jpg').then(function(fileId) {
// fileId 为 group + '/' + filename
console.log(fileId);
}).catch(function(err) {
console.error(err);
);
上传Buffer
var fs = require('fs');
// 注意此处的buffer获取方式只为演示功能,实际不会这么去构建buffer
var buffer = fs.readFileSync('test.gif');
fdfs.upload(buffer).then(function(fileId) {
// fileId 为 group + '/' + filename
console.log(fileId);
}).catch(function(err) {
console.error(err);
);
ReadableStream
var fs = require('fs');
var rs = fs.createReadStream('test.gif');
fdfs.upload(rs).then(function(fileId) {
// fileId 为 group + '/' + filename
console.log(fileId);
}).catch(function(err) {
console.error(err);
);
其他一些options,作为第2个参数传入
fdfs.upload('test.gif', {
// 上传方法 [upload, uploadAppender, append, modify], 默认为upload
method: 'upload',
// 指定文件存储的group,不指定则由tracker server分配
group: 'group1',
// method为append或modify指定追加的源文件
fileId: 'group1/M00/00/0F/wKgBeFXlZJuAdsBZAAPm5H9JxDA153.jpg',
// file bytes, file参数为ReadableStream时必须指定
size: 1024,
// method为modify指定追加的源文件的起始点
offset: 10240,
// 上传文件的后缀,不指定则获取file参数的后缀,不含(.)
ext: 'jpg'
}).then(function(fileId) {
// fileId 为 group + '/' + filename
console.log(fileId);
}).catch(function(err) {
console.error(err);
);
下载到本地
fdfs.download(fileId, 'test_download.gif').then(function() {
// 下载完成
}).catch(function(err) {
console.error(err);
);
下载到WritableStream
var fs = require('fs');
var ws = fs.createWritableStream('test_download.gif');
fdfs.download(fileId, ws).then(function() {
// 下载完成
}).catch(function(err) {
console.error(err);
);
下载文件片段
fdfs.download(fileId, {
target: 'test_download.part',
offset: 5,
bytes: 5
}).then(function() {
// 下载完成
}).catch(function(err) {
console.error(err);
);
fdfs.del(fileId).then(function() {
// 删除成功
}).catch(function(err) {
console.error(err);
);
fdfs.getFileInfo(fileId).then(function(fileInfo) {
// fileInfo有4个属性
// {
// // 文件大小
// size:
// // 文件创建的时间戳,单位为秒
// timestamp:
// // 校验和
// crc32:
// // 最初上传到的storage server的ip
// addr:
// }
console.log(fileInfo);
}).catch(function(err) {
console.error(err);
);
设置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
*/
fdfs.setMetaData(fileId, metaData, flag).then(function() {
// 设置成功
}).catch(function(err) {
console.error(err);
);
获取Meta Data
fdfs.getMetaData(fileId).then(function(metaData) {
console.log(metaData);
}).catch(function(err) {
console.error(err);
);
fdfs.listGroups().then(function(groups) {
console.log(groups);
}).catch(function(err) {
console.error(err);
);
fdfs.listStorages(‘group1’).then(function(storages) {
console.log(storages);
}).catch(function(err) {
console.error(err);
);
FAQs
FastDFS node client
The npm package fdfs receives a total of 178 weekly downloads. As such, fdfs popularity was classified as not popular.
We found that fdfs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A data handling bug in OSV.dev caused disputed CVEs to disappear from vulnerability feeds until a recent fix restored over 500 advisories.
Research
/Security News
175 malicious npm packages (26k+ downloads) used unpkg CDN to host redirect scripts for a credential-phishing campaign targeting 135+ organizations worldwide.
Security News
Python 3.14 adds template strings, deferred annotations, and subinterpreters, plus free-threaded mode, an experimental JIT, and Sigstore verification.