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

js-file-operation

v1.1.5

Published

File upload and file stream Download

Downloads

3

Readme

js-file-operation

文件操作,可以对文件上传,以及对客户端接收的文件流进行下载

install

npm install file-operation --save

功能

文件上传

主要是对文件类型做判断,输出符合条件的文件,uploadFile(file, typeList) 函数,传两个参数,第一个参数是要上传的文件;第二个参数typeList是包含文件后缀名的数组,比如:['png', 'docx', 'txt'] 等文件都可以做出判断。函数执行完会返回一个符合条件的 Promise 文件,可以对得到的文件进行下一步操作

流文件 下载

主要对服务器返回的文件流进行下载(暂时不能下载二进制文件)。内部将文件转换成Blob对象,在通过 URL对象的 createObjectURL方法将Blob对象转换成 url地址。通过创建a标签,点击下载文件。fileStreamDownload(fileStream, fileName) 函数接收两个参数,文件流和文件名。返回结果是一个 Promiseblob下载地址,也可以不取下载地址,直接进行下载。

流文件 读取

主要通过 HTML5 的APIFileReader,自定义功能函数 fileReader(file, type) 接收两个参数,file,是要读取的文件,type是要读取的格式,如果 type === 'image'读取的是图片格式,如果type === 'file'或者不传,则读取的是普通文件,比如(pdf / txt / docx)等。返回结果是一个 Promise,图片类型的结果是 base64 格式的图片,文件结果是文本