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 🙏

© 2025 – Pkg Stats / Ryan Hefner

file-loads

v1.1.0

Published

(携带头信息)资源的预览和下载

Downloads

1

Readme

file-loads

有些时候获取一个资源,请求地址的同时需要携带一些头信息如“token”或者其他,这时候可以使用 file-loads 轻易的实现,资源的预览或下载

( Sometimes you need to take some header information such as "token" or other when you request the address of a resource. You can use file-loads to easily implement, preview or download the resource. )

源码地址(Source address)

安装(Install)

npm install file-loads --save

使用(Usage)

方法(Method)

openFile( type [ , filename] )( url [ , headers] )

参数(Arguments)

type:<String> 类型“open”预览,“download”下载,默认“open”

filename:<String>(可选)文件名

url:<String> 资源地址

headers:<String/Object>(可选)头信息,传token:String默认{authorization:token}

例(example)

import {openFile} from 'file-loads'
/* 类型 open: 预览, download: 下载 */
const type = 'open'
/* 资源地址 */
const url = '/'
/* 设置请求头 接受string和object, string 会转为 {authorization:string} */
const headers = 'token'
/* 文件名 如有类型区分 可省略扩展名,可选 ,默认先从返回头 content-disposition 中取,取不到则为时间戳 */
const filename = '1.jpg'

/* 预览 */
openFile('open')(url,headers)

/* 下载 */
openFile('download', filename)(url, headers)

方法(Method)

uploadFile( url , file [ , headers] )

参数(Arguments)

url:<String> 资源地址

file:<File> 资源,可以从<input type="file">获取

headers:<Object>(可选)头信息

例(example)

import {uploadFile} from 'file-loads'
/* 需要上传的file */
const file = file
/* 上传地址 */
const url = url
/* 设置请求头 */
const headers = {
    authorization: 'token'
}
/* 调用utils.uploadFile */
const result = await uploadFile(url, file, headers)

方法(Method)

asyncToDataUrl( file )

参数(Arguments)

file:<File> 资源,可以从<input type="file">获取

例(example)

import {asyncToDataUrl} from 'file-loads'
/* 转Base64Url */
const url = await asyncToDataUrl(file)