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

@uni/file

v1.1.1

Published

[![npm](https://img.shields.io/npm/v/@uni/file.svg)](https://www.npmjs.com/package/@uni/file)

Downloads

1,685

Readme

file

npm

File operations.

Support

Install

$ npm install @uni/file --save

Methods

getInfo(options)

Get file information.

Support

Parameters

| Property | Type | Default | Required | Description | Support | | --------------- | -------- | ------- | -------- | ------------------------------------------------------------ | --------------------------------------- | | filePath | String | | √ | The file path | | | digestAlgorithm | String | md5 | x | The algorithm to calculate the file summary can be md5, sha1 | |

getSavedInfo(options)

Gets saved file information.

Support

Parameters

| Property | Type | Default | Required | Description | Support | | -------- | -------- | ------- | -------- | ------------- | --------------------------------------- | | filePath | String | | √ | The file path | |

getSavedList(options)

Gets all saved file information.

Support

openDocument(options)

Open a file preview on the new page.

Support

Parameters

| Property | Type | Default | Required | Description | Support | | -------- | -------- | ------- | -------- | ------------- | --------------------------------------- | | filePath | String | | √ | The file path | | | fileType | String | | x | The file Type | |

removeSaved(options)

Delete a saved file.

Support

Parameters

| Property | Type | Default | Required | Description | Support | | -------- | -------- | ------- | -------- | ------------- | --------------------------------------- | | filePath | String | | √ | The file path | |

save(options)

Save the file locally.

Support

Parameters

| Property | Type | Default | Required | Description | Support | | -------- | -------- | ------- | -------- | ------------- | --------------------------------------- | | filePath | String | | √ | The file path | |

upload(options)

Upload local resources to the developer server.

Support

Parameters

| Property | Type | Default | Required | Description | Support | | -------- | -------- | ------- | -------- | ------------------------------------ | --------------------------------------- | | url | String | | √ | Developer server address | | | filePath | String | File Object | | √ | The path to upload the file resource. In web browser, it can be either base64 string or a File object. | | | fileName | String | | √ | File name, that is, the corresponding key, the developer in the server side through this key can get the binary content of the file. | | | fileType | String | | √ | File type supports image, video, audio (image/video/audio). Not required in browser. | | | header | Object | | x | The HTTP request Header | | | formData | Object | | x | Additional form data in the HTTP request | | | withCredentials | Boolean | | x | Custom withCredentials option | | | timeout | Number | | x | Upload timeout | |

Return

Notice: Alipay miniapp only supports client 10.1.35 and above. Please use it with caution because it will destroy one code with multiple platforms. When using it, please make sure that it is not empty, and the upload will return empty under containers that do not support UploadTask.

UploadTask

An object that can monitor upload progress change events and cancel upload tasks. Specific documents can be viewed:

  • WeChat: Link
  • ByteDance: Link
  • BaiDu: Link
  • KuaiShou: Link
  • Alipay: Same as WeChat, but missing onHeadersReceived and offHeadersReceived.
  • Web: Same as WeChat

download(options)

Download file resources locally.

Support

Parameters

| Property | Type | Default | Required | Description | Support | | -------- | -------- | ------- | -------- | ----------------------- | --------------------------------------- | | url | String | | √ | Download file address | | | header | Object | | x | The HTTP request Header | |

Return

注意:只有微信小程序和字节跳动小程序、百度小程序、快手小程序支持,由于破坏了一码多端请谨慎使用

DownloadTask 一个可以监听下载进度变化事件和取消下载的对象 具体文档可以查看: 微信:https://developers.weixin.qq.com/miniprogram/dev/api/network/download/DownloadTask.html 字节跳动:https://microapp.bytedance.com/docs/zh-CN/mini-app/develop/api/network/http/download-task/ 百度:链接 快手:链接

Example

import { download, getInfo, getSavedInfo, getSavedList, openDocument, removeSaved, save, upload } from '@uni/file';

// Get file information.
getInfo({
  filePath: 'https://resource/apml953bb093ebd2834530196f50a4413a87.video',
  digestAlgorithm: 'sha1',
  success: (res)=>{
    console.log(JSON.stringify(res))
  }
});

// You need to save the address to be able to use File.getsavedinfo
getSavedInfo({
  filePath: '**filePath**',
  success: (res) => {
    console.log(res.size);
    console.log(res.createTime);
  }
});

getSavedList({
  success:(res) => {
    console.log(JSON.stringfy(res));
  }
});

openDocument({
  filePath: '**filePath**',
  fileType: 'pdf',
  success: (res) => {
    console.log('open document success');
  };
});

removeSaved({
  filePath: '**filePath**',
  success:(res) => {
    console.log('remove success');
  }
});

save({
  filePath: '**filePath**',
  success:(res) => {
    console.log('save success');
  }
});

upload({
  url: 'http://httpbin.org/post',
  fileType: 'image',
  fileName: 'file',
  filePath: '**filePath**',
  success: res => {
    console.log('upload success');
  },
  fail: res => {
    console.log('upload succefailss');
  },
});

download({
  url: 'http://img.alicdn.com/tfs/TB1x669SXXXXXbdaFXXXXXXXXXX-520-280.jpg',
  success: res => {
    console.log(res.filePath);
  },
  fail: res => {
    console.log(res);
  },
});