
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
slice-upload-utils
Advanced tools
本工具包含上传和下载功能。vite + vue的实现。
为了优化计算hash时间,hash值计算分两种,一直是计算文件的真实MD5,一种是计算自定义hash值。
:: preHash,采用抽样hash算法,截取file前段、中间和末段合成一个新的文件,和file.size一起计算的一个新的hash值。
:: chunkHash,采用preHash结合chunkSize和该切片的index计算hash值。
:: preHash, file文件的hash值,file的真实MD5值计算,在file.size大于chunkSize时,通过计算chunk的web worker线程里面同时计算。
:: chunkHash, file.size 小于chunkSize时,file等于chunk,chunkHash等于preHash;file.size大于chunkSize时在web worker(vite 打包后,npm i 安装使用路径会出问题,故改成直接使用promise)里面计算。
可以根据实例中的isPreHash和isChunkHash的值来判断当前是否计算的真实hash。
pnpm add file-slice-upload
/playground/vue/src/example/Upload.vue
/playground/vue/src/example/Download.vue
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']
}
FAQs
A library for slice upload file and download.
The npm package slice-upload-utils receives a total of 5 weekly downloads. As such, slice-upload-utils popularity was classified as not popular.
We found that slice-upload-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.