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

slice-upload-utils

v0.0.29

Published

A library for slice upload file and download.

Downloads

131

Readme

slice-upload-utils

NPM version

介绍

  • 本工具包含上传和下载功能。vite + vue的实现。

    上传

    • 包括切片上传,秒传,断点续传,暂停、取消。

    下载

    • 切片下载,合并,暂停、取消。

    上传hash计算

    • 为了优化计算hash时间,hash值计算分两种,一直是计算文件的真实MD5,一种是计算自定义hash值。

      自定义hash值:

      :: preHash,采用抽样hash算法,截取file前段、中间和末段合成一个新的文件,和file.size一起计算的一个新的hash值。

      :: chunkHash,采用preHash结合chunkSize和该切片的index计算hash值。

      真实hash值:

      :: preHash, file文件的hash值,file的真实MD5值计算,在file.size大于chunkSize时,通过计算chunk的~~web worker~~线程里面同时计算。

      :: chunkHash, file.size 小于chunkSize时,file等于chunkchunkHash等于preHashfile.size大于chunkSize时在~~web worker~~(vite 打包后,npm i 安装使用路径会出问题,故改成直接使用promise)里面计算。

    • 可以根据实例中的isPreHashisChunkHash的值来判断当前是否计算的真实hash。

快速开始

  • 使用 pnpm 安装
pnpm add file-slice-upload

示例代码

上传

/playground/vue/src/example/Upload.vue

下载

/playground/vue/src/example/Download.vue

下载文件后端代码

koa-download-demo

  • 具体效果可以把代码仓库clone下来,pnpm dev一下。

调用说明

上传

export interface UseSliceUploadOptions {
  /**
   * 上传文件
   */
  file: Ref<File | null | undefined>
  /**
   * 上传请求函数
   */
  request: UploadRequest
  /**
   * 报错处理函数
   */
  onError?: UploadEventType['error']
  /**
   * 上传完成函数
   */
  onFinish?: UploadEventType['finish']
  /**
   * 预检函数
   */
  preVerifyRequest?: PreVerifyUploadRequest
  /**
   * 分片大小
   * @default 1024 * 1024 * 2
   */
  chunkSize?: number
  /**
   * 并发上传数
   * @default 3
   */
  poolCount?: number
  /**
   * 请求失败后,重试次数
   * @default 3
   */
  retryCount?: number
  /**
   * 请求失败后,重试间隔时间
   * @default 300
   */
  retryDelay?: number
  /**
   * 请求超时时间(15s)
   * @default 15000
   */
  timeout?: number
  /**
   * 计算整个文件的hash,开启后比较耗时间
   * @default false
   */
  realPreHash?: boolean
  /**
   * 计算分片文件的hash,开启后比较耗时间
   * @default false
   */
  realChunkHash?: boolean
}

下载

export interface UseSliceDownloadOptions {
  fileSize?: number
  filename?: string
  /**
   * 文件MIME类型
   * @default application/octet-stream
   * @see https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
   */
  fileType?: string
  /**
   * 是否自动保存
   * @default true
   */
  autoSave?: boolean
  /**
   * 分片大小
   * @default 1024 * 1024 * 2
   */
  chunkSize?: number
  /**
   * 并发上传数
   * @default 3
   */
  poolCount?: number
  /**
     * 请求失败后,重试次数
     * @default 3
     */
  retryCount?: number
  /**
     * 请求失败后,重试间隔时间
     * @default 300
     */
  retryDelay?: number
  /**
     * 请求超时时间(15s)
     * @default 15000
     */
  timeout?: number
  /**
   * 上传请求函数
   */
  request: DownloadRequest
  /**
   * 报错处理函数
   */
  onError?: DownloadEventType['error']
  /**
   * 预检函数
   */
  onFinish?: DownloadEventType['finish']
}

License

MIT License © 2023 Ywenhao