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

@hongfangze/filestream

v0.6.1

Published

comm.filestream

Downloads

10

Readme

@hongfangze/filestream 文件操作帮助类

介绍

文件的一些操作

/**
 * 复制文件夹
 * @param {string} src 源地址
 * @param {string} dest 目标地址
 * @param {Boolean} cover 是否覆盖已有文件
 */
const _copyFolder = (src: string, dest: string, cover?: boolean): boolean/**
 * 类似node_module方式读取文件数据
 * @param {string} filename 文件名或者部分路径
 * @param {({ encoding?: null | undefined; flag?: string | undefined; } | null)} [options]
 * @return {*}  {Buffer}
 */
requireFileSync(
    filename: string,
    options?: { encoding?: null | undefined; flag?: string | undefined; } | null
): Buffer

/**
 * 同步创建文件夹,可递归创建
 * @param {String} dir 需要创建的文件夹路径
 * @returns
 */
mkdirSync(dir: string): boolean

/**
 * 创建空白文件
 * @param {String} file 文件路径
 */
mkfileSync(file: string): void

/** 
 * 递归删除文件夹
*/
rmdirSync(path: string): void

/**
 * 递归获取文件名
 * @param {String} dir
 * @returns
 */
findfilesSync(dir: string): string[]

/**
 * 获取文件md5
 * @param {*} file
 * @returns
 */
md5(file: string): Promise<string>

/**
 * 将文件夹打包压缩成zip
 * 
 * @deprecated [#1] version 0.0.3
 * 
 * @param {Array<String>} files 被打包的文件全路径
 * @param {String} filepath 被打包的文件夹
 * @param {String} filename 打包压缩后的文件名全路径,如:/xxx.zip
 * @returns
 */
zip(filepath: string, filename: string): Promise<void>

/**
 * 压缩文件
 * @param {string[]} src 需要压缩的文件集合
 * @return {*}  {Promise<void>}
 */
compressing(src: string[]): Promise<void>
/**
 * 压缩文件
 * @param {string[]} src 需要压缩的文件集合
 * @param {{ path?: string, filename?: string, extname?: string }} dest 压缩文件目标配置,文件路径、名称、扩展名
 * @return {*}  {Promise<void>}
 */
compressing(src: string[], dest: { path?: string, filename?: string, extname?: string }): Promise<void>
/**
 * 压缩文件
 * @param {string[]} src 需要压缩的文件集合
 * @param {{ path?: string, filename?: string, extname?: string }} dest 压缩文件目标配置,文件路径、名称、扩展名
 * @param {('zip' | 'gzip' | 'tar' | 'tgz')} mode 压缩方式
 * @return {*}  {Promise<void>}
 */
compressing(src: string[], dest: { path?: string, filename?: string, extname?: string }, mode: 'zip' | 'gzip' | 'tar' | 'tgz'): Promise<void>

/**
 * 解压文件
 * @param {string} src 源文件地址
 * @return {*}  {Promise<void>}
 */
uncompressing(src: string): Promise<void>;
/**
 * 解压文件
 * @param {string} src 源文件地址
 * @param {string} dest 解压目标地址
 * @return {*}  {Promise<void>}
 */
uncompressing(src: string, dest: string): Promise<void>;
/**
 * 解压文件
 * @param {string} src 源文件地址
 * @param {string} dest 解压目标地址
 * @param {('zip' | 'gzip' | 'tar' | 'tgz')} mode 解压方式,需要与压缩方式一致
 * @return {*}  {Promise<void>}
 */
uncompressing(src: string, dest: string, mode: 'zip' | 'gzip' | 'tar' | 'tgz'): Promise<void>

/**
 * 大文件复制
 * @param {string} src 要复制的文件
 * @param {string} dest 复制的目标文件地址
 * @return {*}  {Promise<void>}
 */
copyLargeFile(src: string, dest: string): Promise<void>

/**
 * 大文件读取
 * @param {string} src 要读取的文件
 * @return {*}  {Promise<string[]>}
 */
readLargeFile(src: string): Promise<string[]> 

/**
 * 复制文件夹
 * @param {string} src 源地址
 * @param {string} dest 目标地址
 * @param {Boolean} cover 是否覆盖已有文件
 */
copyFolder = (src: string, dest: string, cover?: boolean): Promise<boolean

/**
 * 移动文件夹
 * @param {string} src 源地址
 * @param {string} dest 目标地址
 * @param {Boolean} cover 是否覆盖已有文件
 */
moveFolder(src: string, dest: string, cover?: boolean): Promise<boolean>

/**
 * 获取文件的文件类型
 * @param {string} src 文件地址
 * @param {number} [chunkLength] 读取文件前多少字节(只要大于等于幻数所在的字节数即可,如果不确定可以不传)
 * @return {*}  {Promise<{ ext: string, mime: string }>}
 */
const fileType = async (src: string, chunkLength?: number): Promise<{ ext: string, mime: string }>

版本迭代记录

2024-05-18 v0.6.1

  • 修复部分Bug

2024-03-22 v0.6.0

  • 增加fileType函数,基于文件的MagicNumber判断文件的文件类型(修改文件后缀名或删除文件后缀名仍旧可以正确的判断出文件原有的文件类型)

2024-03-14 v0.5.0

  • 添加文件夹复制和移动2个函数