gs-data 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.cn.md +37 -0
- package/README.md +37 -0
- package/lib/index.cjs +1 -0
- package/lib/index.d.ts +441 -0
- package/lib/index.js +1 -0
- package/lib/index.web.js +1 -0
- package/package.json +38 -0
package/README.cn.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# grain-sand-data
|
|
2
|
+
### 中文 | [English](README.md)
|
|
3
|
+
> 在浏览器端读写网络或文件数据的基础性类库<br/>
|
|
4
|
+
> 如果用于本地文件读写,基于本类库的[grain-sand-web-fs](https://www.npmjs.com/package/grain-sand-web-fs)更方便使用<br/>
|
|
5
|
+
> 如果用于网络读取与下载,基于本类库的[grain-sand-fetch](https://www.npmjs.com/package/grain-sand-fetch)更方便使用
|
|
6
|
+
>> 主要包含通过文件内容自动类型分析与扩展名分析
|
|
7
|
+
|
|
8
|
+
> 自动根据内容读取浏览器端常用数据类型
|
|
9
|
+
>>如:文本、图片、html、XML……等
|
|
10
|
+
|
|
11
|
+
> 还包含了一个更利于网络传输,更小于json的SimpleData类型封装
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
```shell
|
|
16
|
+
npx yarn add grain-sand-data
|
|
17
|
+
```
|
|
18
|
+
## 使用
|
|
19
|
+
### 自动判断数据类型 与 数据读取
|
|
20
|
+
```ts
|
|
21
|
+
import {parseMime,getExtensionMime,readBlob} from 'https://cdn.jsdmirror.cn/npm/grain-sand-data/lib/index.web.js'
|
|
22
|
+
|
|
23
|
+
const blob = await fetch('https://emoji.bj.bcebos.com/yige-aigc/index_aigc/final/toolspics/15.png').then(r=>r.blob());
|
|
24
|
+
|
|
25
|
+
const mime = await parseMime(blob)//从blob分析数据类型,图片、文本、视频、切片……等类型皆支持
|
|
26
|
+
|
|
27
|
+
console.log(mime) // 打印输出 image/png
|
|
28
|
+
|
|
29
|
+
const type = await getExtensionMime(mime!)
|
|
30
|
+
console.log(type) // 打印输出 {ext: 'png', mime: 'image/png'}
|
|
31
|
+
|
|
32
|
+
const pkg = await readBlob(blob)
|
|
33
|
+
document.body.appendChild(pkg.result) //将会在页面上显示图片
|
|
34
|
+
|
|
35
|
+
console.log(pkg) //打印输出 {ext: 'png', mime: 'image/png', blob: Blob, type: 2, result: img}
|
|
36
|
+
|
|
37
|
+
```
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# grain-sand-data
|
|
2
|
+
### English | [中文](README.cn.md)
|
|
3
|
+
> A foundational library for reading and writing network or file data on the browser side<br/>
|
|
4
|
+
> For local file read/write operations, [grain-sand-web-fs](https://www.npmjs.com/package/grain-sand-web-fs), built on top of this library, offers enhanced ease of use<br/>
|
|
5
|
+
> For network data reading and downloading, [grain-sand-fetch](https://www.npmjs.com/package/grain-sand-fetch), also based on this library, provides a more convenient solution
|
|
6
|
+
>> The main features include automatic type detection by file content and file extension analysis.
|
|
7
|
+
|
|
8
|
+
> Automatically reads common browser-side data types based on content
|
|
9
|
+
>> e.g., text, images, HTML, XML, etc.
|
|
10
|
+
|
|
11
|
+
> Also includes a SimpleData type wrapper, optimized for network transmission and smaller than JSON
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
```shell
|
|
16
|
+
npx yarn add grain-sand-data
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
### Auto-detecting Data Types and Reading Data
|
|
21
|
+
```ts
|
|
22
|
+
import {parseMime,getExtensionMime,readBlob} from 'https://cdn.jsdmirror.cn/npm/grain-sand-data/lib/index.web.js'
|
|
23
|
+
|
|
24
|
+
const blob = await fetch('https://emoji.bj.bcebos.com/yige-aigc/index_aigc/final/toolspics/15.png').then(r => r.blob());
|
|
25
|
+
|
|
26
|
+
const mime = await parseMime(blob); // Analyze data type from blob, supports images, text, videos, segments, etc.
|
|
27
|
+
|
|
28
|
+
console.log(mime); // Outputs: image/png
|
|
29
|
+
|
|
30
|
+
const type = await getExtensionMime(mime!);
|
|
31
|
+
console.log(type); // Outputs: {ext: 'png', mime: 'image/png'}
|
|
32
|
+
|
|
33
|
+
const pkg = await readBlob(blob);
|
|
34
|
+
document.body.appendChild(pkg.result); // Displays the image on the page
|
|
35
|
+
|
|
36
|
+
console.log(pkg); // Outputs: {ext: 'png', mime: 'image/png', blob: Blob, type: 2, result: img}
|
|
37
|
+
```
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,t,a,i=require("gs-base"),o=require("js-base64");let n;exports.FileMimeTypes=void 0,(a=exports.FileMimeTypes||(exports.FileMimeTypes={})).TextPlain="text/plain",a.TextUTF8="text/plain;charset=UTF-8",a.TextUTF16BE="text/plain;charset=UTF-16BE",a.TextUTF16LE="text/plain;charset=UTF-16LE",a.HTML="text/html",a.CSS="text/css",a.JavaScript="text/javascript",a.XML="text/xml",a.JSON="application/json",a.CSV="text/csv",a.Markdown="text/markdown",a.LaTeX="application/x-latex",a.TSV="text/tab-separated-values",a.Bat="text/x-sh",a.SimpleData="text/x-simpledata",a.JPEG="image/jpeg",a.PNG="image/png",a.GIF="image/gif",a.SVG="image/svg+xml",a.WebP="image/webp",a.BMP="image/bmp",a.TIFF="image/tiff",a.HEIF="image/heif",a.HEIC="image/heic",a.ICO="image/x-icon",a.JPEG2000="image/jp2",a.AdobeXD="application/vnd.adobe.xd",a.PSD="image/vnd.adobe.photoshop",a.MP3="audio/mpeg",a.OGG="audio/ogg",a.WAV="audio/wav",a.AAC="audio/aac",a.FLAC="audio/flac",a.M4A="audio/x-m4a",a.AMR="audio/amr",a.WMA="audio/x-ms-wma",a.MP4="video/mp4",a.MPEG="video/mpeg",a.MP2T="video/MP2T",a.MPEGPS="video/MP1S",a.WebM="video/webm",a.OggVideo="video/ogg",a.QuickTime="video/quicktime",a.AVI="video/x-msvideo",a.MKV="video/x-matroska",a.MOV="video/quicktime",a.FLV="video/x-flv",a.WMV="video/x-ms-wmv",a.PDF="application/pdf",a.EXE="application/vnd.microsoft.portable-executable",a.MSI="application/x-msdownload",a.APK="application/vnd.android.package-archive",a.JAR="application/java-archive",a.DMG="application/x-apple-diskimage",a.ISO="application/x-iso9660-image",a.TTF="font/ttf",a.WOFF="font/woff",a.WOFF2="font/woff2",a.OTF="font/otf",a.EOT="application/vnd.ms-fontobject",a.SVGFont="font/svg+xml",a.DOC="application/msword",a.DOCX="application/vnd.openxmlformats-officedocument.wordprocessingml.document",a.XLS="application/vnd.ms-excel",a.XLSX="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",a.PPT="application/vnd.ms-powerpoint",a.PPTX="application/vnd.openxmlformats-officedocument.presentationml.presentation",a.ODT="application/vnd.oasis.opendocument.text",a.ODS="application/vnd.oasis.opendocument.spreadsheet",a.ODP="application/vnd.oasis.opendocument.presentation",a.RTF="application/rtf",a.Base64="application/base64",a.P7M="application/pkcs7-mime",a.P12="application/x-pkcs12",a.COM="application/x-msdos-program",a.DLL="application/x-msdownload",a.SYS="application/x-mswinexe",a.OLE="application/x-oleobject",a.OctetStream="application/octet-stream",a.UnknownBinary="application/x-unknown",a.Binary="application/x-binary",a.ZIP="application/zip",a.RAR="application/vnd.rar",a.GZIP="application/gzip",a.TAR="application/x-tar",a.BZIP2="application/x-bzip2",a.SEVEN_ZIP="application/x-7z-compressed",a.XZ="application/x-xz",a.GZ="application/x-gzip",a.TAR_GZ="application/gzip",a.LZ="application/x-lzip",a.LZH="application/x-lzh",a.Fbr="application/zip+fbr",a.M3U="audio/x-mpegurl",a.M3U8="application/x-mpegurl",a.PLS="audio/x-scpls",a.XSPF="application/xspf+xml",a.DPL="application/x-daumplaylist",exports.NetMimeTypes=void 0,(t=exports.NetMimeTypes||(exports.NetMimeTypes={})).MIME="message/rfc822",t.SMTP="application/smtp",t.HTTP="application/http",t.HTTPS="application/https",t.FTP="application/ftp",t.TCP="application/tcp",t.UDP="application/udp",t.JSONLD="application/ld+json",t.WebAssembly="application/wasm",t.SVGZ="image/svg+xml+gzip",t.MHTML="multipart/related",t.OGG="application/ogg",t.XAP="application/x-silverlight-app",t.WOFF="font/woff",t.WASM="application/wasm",t.WGT="application/widget",t.OctetStream="application/octet-stream",t.UnknownBinary="application/x-unknown",exports.MimeTypes=void 0,(e=exports.MimeTypes||(exports.MimeTypes={})).SimpleData="text/x-simpledata",e.Fbr="application/zip+fbr",e.PSD="image/vnd.adobe.photoshop",e.Bat="text/x-sh",e.TextPlain="text/plain",e.TextUTF8="text/plain;charset=UTF-8",e.TextUTF16LE="text/plain;charset=UTF-16LE",e.TextUTF16BE="text/plain;charset=UTF-16BE",e.HTML="text/html",e.CSS="text/css",e.JavaScript="text/javascript",e.XML="text/xml",e.JSON="application/json",e.CSV="text/csv",e.Markdown="text/markdown",e.RTF="application/rtf",e.LaTeX="application/x-latex",e.TSV="text/tab-separated-values",e.JPEG="image/jpeg",e.PNG="image/png",e.GIF="image/gif",e.SVG="image/svg+xml",e.WebP="image/webp",e.BMP="image/bmp",e.TIFF="image/tiff",e.HEIF="image/heif",e.HEIC="image/heic",e.ICO="image/x-icon",e.JPEG2000="image/jp2",e.MP3="audio/mpeg",e.OGG="audio/ogg",e.WAV="audio/wav",e.AAC="audio/aac",e.FLAC="audio/flac",e.M4A="audio/x-m4a",e.AMR="audio/amr",e.WMA="audio/x-ms-wma",e.MP4="video/mp4",e.MPEG="video/mpeg",e.MP2T="video/MP2T",e.MPEGPS="video/MP1S",e.WebM="video/webm",e.OggVideo="video/ogg",e.QuickTime="video/quicktime",e.AVI="video/x-msvideo",e.MKV="video/x-matroska",e.MOV="video/quicktime",e.FLV="video/x-flv",e.WMV="video/x-ms-wmv",e.PDF="application/pdf",e.ZIP="application/zip",e.RAR="application/vnd.rar",e.SEVEN_ZIP="application/x-7z-compressed",e.GZIP="application/gzip",e.TAR="application/x-tar",e.EXE="application/vnd.microsoft.portable-executable",e.MSI="application/x-msdownload",e.APK="application/vnd.android.package-archive",e.JAR="application/java-archive",e.DMG="application/x-apple-diskimage",e.ISO="application/x-iso9660-image",e.TTF="font/ttf",e.WOFF="font/woff",e.WOFF2="font/woff2",e.OTF="font/otf",e.EOT="application/vnd.ms-fontobject",e.SVGFont="font/svg+xml",e.DOC="application/msword",e.DOCX="application/vnd.openxmlformats-officedocument.wordprocessingml.document",e.AdobeXD="application/vnd.adobe.xd",e.XLS="application/vnd.ms-excel",e.XLSX="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",e.PPT="application/vnd.ms-powerpoint",e.PPTX="application/vnd.openxmlformats-officedocument.presentationml.presentation",e.ODT="application/vnd.oasis.opendocument.text",e.ODS="application/vnd.oasis.opendocument.spreadsheet",e.ODP="application/vnd.oasis.opendocument.presentation",e.Base64="application/base64",e.P7M="application/pkcs7-mime",e.P12="application/x-pkcs12",e.XZ="application/x-xz",e.BZIP2="application/x-bzip2",e.GZ="application/x-gzip",e.TAR_GZ="application/gzip",e.LZ="application/x-lzip",e.LZH="application/x-lzh",e.COM="application/x-msdos-program",e.DLL="application/x-msdownload",e.SYS="application/x-mswinexe",e.OLE="application/x-oleobject",e.Binary="application/x-binary",e.MIME="message/rfc822",e.SMTP="application/smtp",e.HTTP="application/http",e.HTTPS="application/https",e.FTP="application/ftp",e.TCP="application/tcp",e.UDP="application/udp",e.JSONLD="application/ld+json",e.WebAssembly="application/wasm",e.SVGZ="image/svg+xml+gzip",e.MHTML="multipart/related",e.XAP="application/x-silverlight-app",e.WASM="application/wasm",e.WGT="application/widget",e.OctetStream="application/octet-stream",e.UnknownBinary="application/x-unknown",e.M3U="audio/x-mpegurl",e.M3U8="application/x-mpegurl",e.PLS="audio/x-scpls",e.XSPF="application/xspf+xml",e.DPL="application/x-daumplaylist";const p=()=>n||(n={"text/x-simpledata":"txt","text/plain":"txt","text/html":"html","text/css":"css","text/javascript":"js","text/xml":"xml","application/json":"json","text/csv":"csv","text/markdown":"md","application/x-latex":"tex","text/tab-separated-values":"tsv","text/x-sh":"bat","image/jpeg":"jpg","image/png":"png","image/gif":"gif","image/svg+xml":"svg","image/webp":"webp","image/bmp":"bmp","image/tiff":"tiff","image/heif":"heif","image/heic":"heic","image/x-icon":"ico","image/jp2":"jp2","audio/mpeg":"mp3","audio/ogg":"ogg","audio/wav":"wav","audio/aac":"aac","audio/flac":"flac","audio/x-m4a":"m4a","audio/amr":"amr","audio/x-ms-wma":"wma","video/mp4":"mp4","video/webm":"webm","video/ogg":"ogg","video/quicktime":"mov","video/x-msvideo":"avi","video/x-matroska":"mkv","video/x-flv":"flv","video/x-ms-wmv":"wmv","application/pdf":"pdf","application/zip":"zip","application/vnd.rar":"rar","application/gzip":"gzip","application/x-tar":"tar","application/vnd.microsoft.portable-executable":"exe","application/x-msdownload":"msi","application/vnd.android.package-archive":"apk","application/java-archive":"jar","application/x-apple-diskimage":"dmg","application/x-iso9660-image":"iso","application/zip+fbr":"fbr","font/ttf":"ttf","font/woff":"woff","font/woff2":"woff2","font/otf":"otf","application/vnd.ms-fontobject":"eot","font/svg+xml":"svgfont","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","application/vnd.oasis.opendocument.text":"odt","application/vnd.oasis.opendocument.spreadsheet":"ods","application/vnd.oasis.opendocument.presentation":"odp","application/octet-stream":"exe","application/x-unknown":"unknown","audio/x-mpegurl":"m3u","application/x-mpegurl":"m3u8","audio/x-scpls":"pls","application/xspf+xml":"xspf","application/x-daumplaylist":"dpl"});let s;const c=/^\.?(\w+)(?:\/([0-9a-z-+.]+)\s*(?:;.*charset\s*=\s*([0-9a-z-]+).*)?)?$/i;function r(e){const t=c.exec(e);let a,o;return t?.[2]?(a=`${t[1]}/${t[2]}`,o=p()?.[a]||"unknown"):t?.[1]&&(o=t[1],a=(s||(s=i.invertRecordKv(p())),s)[o]||"application/x-unknown"),t?.[3]&&(a=`${a}; charset=${t[3]}`),{ext:o,mime:a}}let l;async function m(e,t,a=0){let i;return i=e instanceof Blob?new Uint8Array(await e.slice(a,t).arrayBuffer()):e instanceof ArrayBuffer?new Uint8Array(e.slice(a,t)):e.slice(a,t),i}async function d(e,t,a=0){return(new TextDecoder).decode(await m(e,t,a))}async function x(e){const t=await async function(e,t,a=0){return Array.from(await m(e,t,a)).map((e=>e.toString(16).padStart(2,"0"))).join("").toUpperCase()}(e,8);for(const[e,a]of l||(l=[["EFBBBF","text/plain;charset=UTF-8"],["FEFF","text/plain;charset=UTF-16BE"],["FFFE","text/plain;charset=UTF-16LE"],["FFD8FF","image/jpeg"],["89504E47","image/png"],["47494638","image/gif"],["49492A00","image/tiff"],["4D4D002A","image/tiff"],["424D","image/bmp"],["00000100","image/x-icon"],["38425053","image/vnd.adobe.photoshop"],["52494646","image/webp"],["57454250","image/webp"],["494433","audio/mpeg"],["4F676753","audio/ogg"],["57415645","audio/wav"],["664C6143","audio/flac"],["000001BA","video/MP1S"],["000001BA","video/mpeg"],["000001B3","video/mpeg"],["1A45DFA3","video/x-matroska"],["6674797069736F6D","video/mp4"],["0000001866747970","video/mp4"],["667479706d703432","video/mp4"],["47","video/MP2T"],["1A45DFA3","video/webm"],["504B0304","application/zip"],["52617221","application/vnd.rar"],["1F8B08","application/gzip"],["75737461","application/x-tar"],["425A68","application/x-bzip2"],["377ABCAF271C","application/x-7z-compressed"],["25504446","application/pdf"],["D0CF11E0A1B11AE1","application/msword"],["7B5C727466","application/rtf"],["4D5A","application/vnd.microsoft.portable-executable"],["FFD8FFE0","image/jpeg"],["MZ","application/octet-stream"]]))if(t.startsWith(e))return a}const f=[["word/","application/vnd.openxmlformats-officedocument.wordprocessingml.document"],["ppt/","application/vnd.openxmlformats-officedocument.presentationml.presentation"],["xl/","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],["@Uu","application/zip+fbr"],["mimetypeapplication/","application/vnd.adobe.xd"]];const u="//",g="SimpleData,",v=new RegExp(`^(${g})?(\\{.*\\}|\\[.*\\])$`,"i"),w=[[/^<(!DOCTYPE\s+)?html/i,"text/html"],[/^<svg/i,"image/svg+xml"],[/^<(\?xml|\w+)/i,"text/xml"],[/^[{\[]/i,"application/json"],[/^8BPS/i,"image/vnd.adobe.photoshop"],[/^@?(echo|chcp|set)/i,"text/x-sh"],[new RegExp(`^${g}`,"i"),"text/x-simpledata"],[/^DAUMPLAYLIST/i,"application/x-daumplaylist"]];async function b(e){const t=(await d(e,50)).trim();for(const[e,a]of w)if(e.test(t))return a}const h=/stream|unknown|binary|text|xml'/;async function T(e){const t=e.type||"";if(t&&!h.test(t))return t;let a=t?.includes("text/plain")?await b(e):"";if(a)return a;const i=await x(e);return/zip$/.test(i)?await async function(e){const t=await d(e,50,30);for(const[e,a]of f)if(t.includes(e))return a;return"application/zip"}(e):(a=!i||i.includes("text/plain")?await b(e):"",h.test(i)?a||t||i||void 0:a||i||t||void 0)}const y=o.decode,S=o.encode;async function F(e,t="gzip"){const a=new CompressionStream(t),i=a.writable.getWriter();return i.write(e instanceof Uint8Array?e:new Uint8Array(e)),i.close(),await new Response(a.readable).arrayBuffer()}async function P(e,t="gzip"){const a=new DecompressionStream(t),i=a.writable.getWriter();i.write(e instanceof Uint8Array?e:new Uint8Array(e)),i.close();const o=a.readable;return await new Response(o).arrayBuffer()}async function M(e,t="gzip"){return await F((new TextEncoder).encode(e),t)}async function A(e,t="gzip"){const a=atob(e),i=a.length,o=new Uint8Array(i);for(let e=0;e<i;e++)o[e]=a.charCodeAt(e);return await P(o,t)}async function D(e){if(e.fields)return B(e.fields,e.excludeFields);const t=await async function(e,t=30){const a=[];let o=1;if(i.isIterable(e)){for(const i of e)if(a.push(i),++o>t)break}else if(i.isAsyncIterable(e))for await(const i of e)if(a.push(i),++o>t)break;return a}(e.data),a={};let o,n=0;for(const e of t){const t=Object.keys(e).length;t>n&&(n=t,o=e)}n=0;for(const e in o)a[e]=n++;return B(a,e.excludeFields)}function O(e){return Object.entries(e).sort(E)}function B(e,t){if(!t)return e;const a={},i=Object.entries(e).sort(E);let o=0;for(const[e]of i)t.includes(e)||(a[e]=o++);return a}function E(e,t){return e[1]-t[1]}function z(e,t){const a=[];for(const[i]of e)a.push(t[i]);const i=JSON.stringify(a);return i.slice(1,i.length-1)}class j{_arg;constructor(e){this._arg=e}async*[Symbol.asyncIterator](){const{header:e,exportData:t}=this._arg;yield`${g}${JSON.stringify(e)}`;for(const e of t){const t=await D(e),a=O(t),o={name:e.name,fields:t};if(e.description&&(o.description=e.description),e.extraData&&(o.extraData=e.extraData),e.defaultValues&&(o.defaultValues=e.defaultValues),yield`${u}${JSON.stringify(o)}`,i.isIterable(e.data))for(const t of e.data)yield z(a,t);else if(i.isAsyncIterable(e.data))for await(const t of e.data)yield z(a,t)}}destroy(){delete this._arg}}const k=/^\s*$/;class R{_textReader;constructor(e){i.isString(e)?this._textReader=new i.StringTextReader(e):this._textReader=e}getHeader(){const e=this._textReader.firstLine;return e&&v.exec(e)?.[2]||{}}getSize(){return this._textReader.size}*read(e){let t,a,o;for(const{data:n,progress:p}of this._textReader){if(k.test(n))continue;if(n.startsWith(u)){if(o=JSON.parse(n.slice(2)),t&&t===e)return;t=o.name,a=[];for(const[e,t]of Object.entries(o.fields))a.push([e,Number(t)]);continue}if(!t||!a||e&&t!==e)continue;const s=JSON.parse(`[${n}]`),c=o?.defaultValues?i.copyObject(o?.defaultValues):{};for(const[e,t]of a)c[e]=s[t];yield{name:t,data:c,progress:p,meta:o}}}getAll(e){const t=[];for(const{data:a}of this.read(e))t.push(a);return t}async pageRead(e,t=1e3){let a=[];const i=this._textReader.size;let o,n;for(const{name:i,data:p,progress:s,meta:c}of this.read())a.push(p),a.length>=t?(await e(i,a,s,c),a=[]):(o=i,n=c);a.length&&await e(o,a,i,n)}async namedRead(e,t=1e3){await this.pageRead((async(t,a,i,o)=>{t in e&&await e[t](a,i,o)}),t)}destroy(){try{this._textReader?.destroy?.()}finally{delete this._textReader}}}var L;function C(e,t,a){return new Promise(((i,o)=>{const n=new FileReader;n.onload=()=>{i(n.result)},n.onerror=o,n[t](e,a)}))}exports.BlobTypes=void 0,(L=exports.BlobTypes||(exports.BlobTypes={}))[L.Text=1]="Text",L[L.Base64=2]="Base64",L[L.Image=3]="Image",L[L.Bitmap=4]="Bitmap",L[L.Svg=5]="Svg",L[L.Html=6]="Html",L[L.Xml=7]="Xml",L[L.Json=8]="Json",L[L.SimpleData=9]="SimpleData",L[L.NotSupped=10]="NotSupped";const U=[1,6,5,7,8,9],I=/<meta[^>]+charset\s*=\s*["']?([\w-]+)|^<\?xml[^>]+encoding\s*=\s*"?([\w-]+)/i;function G(e,t){return(new globalThis.DOMParser).parseFromString(e,t)}const V=[2,3];function W(e){switch(e){case"text/plain":return 1;case"application/base64":return 2;case"image/jpeg":case"image/png":case"image/gif":case"image/webp":case"image/bmp":case"image/x-icon":return 3;case"image/svg+xml":return 5;case"text/html":return 6;case"text/xml":return 7;case"application/json":return 8;case"text/x-simpledata":return 9;default:return 10}}exports.NamedWeakMap=class{valueCreator;objectRefs={};constructor(e){this.valueCreator=e}get(e){let t=this.objectRefs[e]?.deref();return t||(this.valueCreator&&this.set(e,t=this.valueCreator(e)),t)}set(e,t){this.objectRefs[e]=new WeakRef(t)}destroy(){for(let e in this.objectRefs)this.objectRefs[e]?.deref()||delete this.objectRefs[e]}},exports.SimpleDataExport=j,exports.SimpleDataReader=R,exports.base64ToBlob=function(e,t){const a=e.indexOf(";base64,");a>-1&&(e=e.slice(a+8));const i=atob(e),o=i.length,n=new Uint8Array(o);for(let e=0;e<o;e++)n[e]=i.charCodeAt(e);return new Blob([n],{type:t})},exports.compressData=F,exports.compressText=M,exports.compressTextToBase64=async function(e,t="gzip"){return btoa(String.fromCharCode(...new Uint8Array(await M(e,t))))},exports.compressToBase64=async function(e,t="gzip"){return btoa(String.fromCharCode(...new Uint8Array(await F(e,t))))},exports.decodeBase64=y,exports.decompressData=P,exports.decompressFromBase64=A,exports.decompressText=async function(e,t="gzip"){return(new TextDecoder).decode(await P(e,t))},exports.decompressTextFromBase64=async function(e,t="gzip"){return(new TextDecoder).decode(await A(e,t))},exports.encodeBase64=S,exports.exportSimpleData=e=>i.joinAsyncIterable(new j(e)),exports.getExtensionMime=r,exports.miniToBlobType=W,exports.parseMime=T,exports.parseMimeExt=async function(e){return r(`${await T(e)}`)},exports.readBlob=async function(e,...t){let a=0;const o=i.isNumber(t[a])?t[a++]:void 0,n=i.isString(t[a])?t[a++]:void 0,p=!o&&await T(e),s=o||W(p);let c;return 4===s?c=await globalThis.createImageBitmap(e):U.includes(s)?c=await async function(e,t,a){if(!a){const[,t,i]=I.exec(await e.slice(0,1024).text())||[];a=t||i}const i=await C(e,"readAsText",a);switch(t){case 5:return G(i,"image/svg+xml").querySelector("svg");case 7:return G(i,"text/xml");case 6:return G(i,"text/html");case 9:return new R(i);case 8:return JSON.parse(i);default:return i}}(e,s,n):V.includes(s)&&(c=await function(e,t){return new Promise((async(a,i)=>{const o=await C(e,"readAsDataURL");if(3===t){const e=new globalThis.Image;e.onload=()=>a(e),e.onerror=i,e.src=o}else a(o)}))}(e,s)),o&&10!==s?c:{...r(p),blob:e,type:s,result:c}},exports.readBlobData=C,exports.supportsCompression=function(){return typeof CompressionStream<"u"&&typeof DecompressionStream<"u"};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import { IDisposable, ITextReader, EncodingType } from 'gs-base';
|
|
2
|
+
|
|
3
|
+
declare const enum FileMimeTypes {
|
|
4
|
+
TextPlain = "text/plain",
|
|
5
|
+
TextUTF8 = "text/plain;charset=UTF-8",
|
|
6
|
+
TextUTF16BE = "text/plain;charset=UTF-16BE",
|
|
7
|
+
TextUTF16LE = "text/plain;charset=UTF-16LE",
|
|
8
|
+
HTML = "text/html",
|
|
9
|
+
CSS = "text/css",
|
|
10
|
+
JavaScript = "text/javascript",
|
|
11
|
+
XML = "text/xml",
|
|
12
|
+
JSON = "application/json",
|
|
13
|
+
CSV = "text/csv",
|
|
14
|
+
Markdown = "text/markdown",
|
|
15
|
+
LaTeX = "application/x-latex",
|
|
16
|
+
TSV = "text/tab-separated-values",
|
|
17
|
+
Bat = "text/x-sh",
|
|
18
|
+
SimpleData = "text/x-simpledata",
|
|
19
|
+
JPEG = "image/jpeg",
|
|
20
|
+
PNG = "image/png",
|
|
21
|
+
GIF = "image/gif",
|
|
22
|
+
SVG = "image/svg+xml",
|
|
23
|
+
WebP = "image/webp",
|
|
24
|
+
BMP = "image/bmp",
|
|
25
|
+
TIFF = "image/tiff",
|
|
26
|
+
HEIF = "image/heif",
|
|
27
|
+
HEIC = "image/heic",
|
|
28
|
+
ICO = "image/x-icon",
|
|
29
|
+
JPEG2000 = "image/jp2",
|
|
30
|
+
AdobeXD = "application/vnd.adobe.xd",
|
|
31
|
+
PSD = "image/vnd.adobe.photoshop",
|
|
32
|
+
MP3 = "audio/mpeg",
|
|
33
|
+
OGG = "audio/ogg",
|
|
34
|
+
WAV = "audio/wav",
|
|
35
|
+
AAC = "audio/aac",
|
|
36
|
+
FLAC = "audio/flac",
|
|
37
|
+
M4A = "audio/x-m4a",
|
|
38
|
+
AMR = "audio/amr",
|
|
39
|
+
WMA = "audio/x-ms-wma",
|
|
40
|
+
MP4 = "video/mp4",
|
|
41
|
+
MPEG = "video/mpeg",
|
|
42
|
+
MP2T = "video/MP2T",
|
|
43
|
+
MPEGPS = "video/MP1S",
|
|
44
|
+
WebM = "video/webm",
|
|
45
|
+
OggVideo = "video/ogg",
|
|
46
|
+
QuickTime = "video/quicktime",
|
|
47
|
+
AVI = "video/x-msvideo",
|
|
48
|
+
MKV = "video/x-matroska",
|
|
49
|
+
MOV = "video/quicktime",
|
|
50
|
+
FLV = "video/x-flv",
|
|
51
|
+
WMV = "video/x-ms-wmv",
|
|
52
|
+
PDF = "application/pdf",
|
|
53
|
+
EXE = "application/vnd.microsoft.portable-executable",
|
|
54
|
+
MSI = "application/x-msdownload",
|
|
55
|
+
APK = "application/vnd.android.package-archive",
|
|
56
|
+
JAR = "application/java-archive",
|
|
57
|
+
DMG = "application/x-apple-diskimage",
|
|
58
|
+
ISO = "application/x-iso9660-image",
|
|
59
|
+
TTF = "font/ttf",
|
|
60
|
+
WOFF = "font/woff",
|
|
61
|
+
WOFF2 = "font/woff2",
|
|
62
|
+
OTF = "font/otf",
|
|
63
|
+
EOT = "application/vnd.ms-fontobject",
|
|
64
|
+
SVGFont = "font/svg+xml",
|
|
65
|
+
DOC = "application/msword",
|
|
66
|
+
DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
67
|
+
XLS = "application/vnd.ms-excel",
|
|
68
|
+
XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
69
|
+
PPT = "application/vnd.ms-powerpoint",
|
|
70
|
+
PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
71
|
+
ODT = "application/vnd.oasis.opendocument.text",
|
|
72
|
+
ODS = "application/vnd.oasis.opendocument.spreadsheet",
|
|
73
|
+
ODP = "application/vnd.oasis.opendocument.presentation",
|
|
74
|
+
RTF = "application/rtf",
|
|
75
|
+
Base64 = "application/base64",
|
|
76
|
+
P7M = "application/pkcs7-mime",
|
|
77
|
+
P12 = "application/x-pkcs12",
|
|
78
|
+
COM = "application/x-msdos-program",
|
|
79
|
+
DLL = "application/x-msdownload",
|
|
80
|
+
SYS = "application/x-mswinexe",
|
|
81
|
+
OLE = "application/x-oleobject",
|
|
82
|
+
OctetStream = "application/octet-stream",
|
|
83
|
+
UnknownBinary = "application/x-unknown",
|
|
84
|
+
Binary = "application/x-binary",
|
|
85
|
+
ZIP = "application/zip",
|
|
86
|
+
RAR = "application/vnd.rar",
|
|
87
|
+
GZIP = "application/gzip",
|
|
88
|
+
TAR = "application/x-tar",
|
|
89
|
+
BZIP2 = "application/x-bzip2",
|
|
90
|
+
SEVEN_ZIP = "application/x-7z-compressed",
|
|
91
|
+
XZ = "application/x-xz",
|
|
92
|
+
GZ = "application/x-gzip",
|
|
93
|
+
TAR_GZ = "application/gzip",
|
|
94
|
+
LZ = "application/x-lzip",
|
|
95
|
+
LZH = "application/x-lzh",
|
|
96
|
+
Fbr = "application/zip+fbr",
|
|
97
|
+
M3U = "audio/x-mpegurl",
|
|
98
|
+
M3U8 = "application/x-mpegurl",
|
|
99
|
+
PLS = "audio/x-scpls",
|
|
100
|
+
XSPF = "application/xspf+xml",
|
|
101
|
+
DPL = "application/x-daumplaylist"
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare const enum NetMimeTypes {
|
|
105
|
+
MIME = "message/rfc822",
|
|
106
|
+
SMTP = "application/smtp",
|
|
107
|
+
HTTP = "application/http",
|
|
108
|
+
HTTPS = "application/https",
|
|
109
|
+
FTP = "application/ftp",
|
|
110
|
+
TCP = "application/tcp",
|
|
111
|
+
UDP = "application/udp",
|
|
112
|
+
JSONLD = "application/ld+json",
|
|
113
|
+
WebAssembly = "application/wasm",
|
|
114
|
+
SVGZ = "image/svg+xml+gzip",
|
|
115
|
+
MHTML = "multipart/related",
|
|
116
|
+
OGG = "application/ogg",
|
|
117
|
+
XAP = "application/x-silverlight-app",
|
|
118
|
+
WOFF = "font/woff",
|
|
119
|
+
WASM = "application/wasm",
|
|
120
|
+
WGT = "application/widget",
|
|
121
|
+
OctetStream = "application/octet-stream",
|
|
122
|
+
UnknownBinary = "application/x-unknown"
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
declare const enum MimeTypes {
|
|
126
|
+
SimpleData = "text/x-simpledata",
|
|
127
|
+
Fbr = "application/zip+fbr",
|
|
128
|
+
PSD = "image/vnd.adobe.photoshop",
|
|
129
|
+
Bat = "text/x-sh",
|
|
130
|
+
TextPlain = "text/plain",
|
|
131
|
+
TextUTF8 = "text/plain;charset=UTF-8",
|
|
132
|
+
TextUTF16LE = "text/plain;charset=UTF-16LE",
|
|
133
|
+
TextUTF16BE = "text/plain;charset=UTF-16BE",
|
|
134
|
+
HTML = "text/html",
|
|
135
|
+
CSS = "text/css",
|
|
136
|
+
JavaScript = "text/javascript",
|
|
137
|
+
XML = "text/xml",
|
|
138
|
+
JSON = "application/json",
|
|
139
|
+
CSV = "text/csv",
|
|
140
|
+
Markdown = "text/markdown",
|
|
141
|
+
RTF = "application/rtf",
|
|
142
|
+
LaTeX = "application/x-latex",
|
|
143
|
+
TSV = "text/tab-separated-values",
|
|
144
|
+
JPEG = "image/jpeg",
|
|
145
|
+
PNG = "image/png",
|
|
146
|
+
GIF = "image/gif",
|
|
147
|
+
SVG = "image/svg+xml",
|
|
148
|
+
WebP = "image/webp",
|
|
149
|
+
BMP = "image/bmp",
|
|
150
|
+
TIFF = "image/tiff",
|
|
151
|
+
HEIF = "image/heif",
|
|
152
|
+
HEIC = "image/heic",
|
|
153
|
+
ICO = "image/x-icon",
|
|
154
|
+
JPEG2000 = "image/jp2",
|
|
155
|
+
MP3 = "audio/mpeg",
|
|
156
|
+
OGG = "audio/ogg",
|
|
157
|
+
WAV = "audio/wav",
|
|
158
|
+
AAC = "audio/aac",
|
|
159
|
+
FLAC = "audio/flac",
|
|
160
|
+
M4A = "audio/x-m4a",
|
|
161
|
+
AMR = "audio/amr",
|
|
162
|
+
WMA = "audio/x-ms-wma",
|
|
163
|
+
MP4 = "video/mp4",
|
|
164
|
+
MPEG = "video/mpeg",
|
|
165
|
+
MP2T = "video/MP2T",
|
|
166
|
+
MPEGPS = "video/MP1S",
|
|
167
|
+
WebM = "video/webm",
|
|
168
|
+
OggVideo = "video/ogg",
|
|
169
|
+
QuickTime = "video/quicktime",
|
|
170
|
+
AVI = "video/x-msvideo",
|
|
171
|
+
MKV = "video/x-matroska",
|
|
172
|
+
MOV = "video/quicktime",
|
|
173
|
+
FLV = "video/x-flv",
|
|
174
|
+
WMV = "video/x-ms-wmv",
|
|
175
|
+
PDF = "application/pdf",
|
|
176
|
+
ZIP = "application/zip",
|
|
177
|
+
RAR = "application/vnd.rar",
|
|
178
|
+
SEVEN_ZIP = "application/x-7z-compressed",
|
|
179
|
+
GZIP = "application/gzip",
|
|
180
|
+
TAR = "application/x-tar",
|
|
181
|
+
EXE = "application/vnd.microsoft.portable-executable",
|
|
182
|
+
MSI = "application/x-msdownload",
|
|
183
|
+
APK = "application/vnd.android.package-archive",
|
|
184
|
+
JAR = "application/java-archive",
|
|
185
|
+
DMG = "application/x-apple-diskimage",
|
|
186
|
+
ISO = "application/x-iso9660-image",
|
|
187
|
+
TTF = "font/ttf",
|
|
188
|
+
WOFF = "font/woff",
|
|
189
|
+
WOFF2 = "font/woff2",
|
|
190
|
+
OTF = "font/otf",
|
|
191
|
+
EOT = "application/vnd.ms-fontobject",
|
|
192
|
+
SVGFont = "font/svg+xml",
|
|
193
|
+
DOC = "application/msword",
|
|
194
|
+
DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
195
|
+
AdobeXD = "application/vnd.adobe.xd",
|
|
196
|
+
XLS = "application/vnd.ms-excel",
|
|
197
|
+
XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
198
|
+
PPT = "application/vnd.ms-powerpoint",
|
|
199
|
+
PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
200
|
+
ODT = "application/vnd.oasis.opendocument.text",
|
|
201
|
+
ODS = "application/vnd.oasis.opendocument.spreadsheet",
|
|
202
|
+
ODP = "application/vnd.oasis.opendocument.presentation",
|
|
203
|
+
Base64 = "application/base64",
|
|
204
|
+
P7M = "application/pkcs7-mime",
|
|
205
|
+
P12 = "application/x-pkcs12",
|
|
206
|
+
XZ = "application/x-xz",
|
|
207
|
+
BZIP2 = "application/x-bzip2",
|
|
208
|
+
GZ = "application/x-gzip",
|
|
209
|
+
TAR_GZ = "application/gzip",
|
|
210
|
+
LZ = "application/x-lzip",
|
|
211
|
+
LZH = "application/x-lzh",
|
|
212
|
+
COM = "application/x-msdos-program",
|
|
213
|
+
DLL = "application/x-msdownload",
|
|
214
|
+
SYS = "application/x-mswinexe",
|
|
215
|
+
OLE = "application/x-oleobject",
|
|
216
|
+
Binary = "application/x-binary",
|
|
217
|
+
MIME = "message/rfc822",
|
|
218
|
+
SMTP = "application/smtp",
|
|
219
|
+
HTTP = "application/http",
|
|
220
|
+
HTTPS = "application/https",
|
|
221
|
+
FTP = "application/ftp",
|
|
222
|
+
TCP = "application/tcp",
|
|
223
|
+
UDP = "application/udp",
|
|
224
|
+
JSONLD = "application/ld+json",
|
|
225
|
+
WebAssembly = "application/wasm",
|
|
226
|
+
SVGZ = "image/svg+xml+gzip",
|
|
227
|
+
MHTML = "multipart/related",
|
|
228
|
+
XAP = "application/x-silverlight-app",
|
|
229
|
+
WASM = "application/wasm",
|
|
230
|
+
WGT = "application/widget",
|
|
231
|
+
OctetStream = "application/octet-stream",
|
|
232
|
+
UnknownBinary = "application/x-unknown",
|
|
233
|
+
M3U = "audio/x-mpegurl",
|
|
234
|
+
M3U8 = "application/x-mpegurl",
|
|
235
|
+
PLS = "audio/x-scpls",
|
|
236
|
+
XSPF = "application/xspf+xml",
|
|
237
|
+
DPL = "application/x-daumplaylist"
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
type FullMimeType = MimeTypes | `${MimeTypes};${string}`;
|
|
241
|
+
interface IExtensionMime {
|
|
242
|
+
ext: string;
|
|
243
|
+
mime: FullMimeType;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
declare function getExtensionMime(extOrMine: string): IExtensionMime;
|
|
247
|
+
|
|
248
|
+
declare function parseMime(header: Uint8Array | ArrayBuffer | Blob): Promise<MimeTypes | undefined>;
|
|
249
|
+
|
|
250
|
+
declare function parseMimeExt(header: Uint8Array | ArrayBuffer | Blob): Promise<IExtensionMime>;
|
|
251
|
+
|
|
252
|
+
type Base64DataURL = `data:${string};base64,${string}`;
|
|
253
|
+
declare const decodeBase64: (input: string) => string;
|
|
254
|
+
declare const encodeBase64: (input: string) => string;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* 测试当前运行环境是否支持压缩
|
|
258
|
+
*/
|
|
259
|
+
declare function supportsCompression(): boolean;
|
|
260
|
+
/**
|
|
261
|
+
* 压缩
|
|
262
|
+
* @param data
|
|
263
|
+
* @param format
|
|
264
|
+
*/
|
|
265
|
+
declare function compressData(data: ArrayBuffer | Uint8Array, format?: 'gzip' | 'deflate' | 'deflate-raw'): Promise<ArrayBuffer>;
|
|
266
|
+
/**
|
|
267
|
+
* 解压
|
|
268
|
+
* @param compressedData
|
|
269
|
+
* @param format
|
|
270
|
+
*/
|
|
271
|
+
declare function decompressData(compressedData: ArrayBuffer | Uint8Array, format?: 'gzip' | 'deflate' | 'deflate-raw'): Promise<ArrayBuffer>;
|
|
272
|
+
/**
|
|
273
|
+
* 压缩文本
|
|
274
|
+
* @param data
|
|
275
|
+
* @param format
|
|
276
|
+
*/
|
|
277
|
+
declare function compressText(data: string, format?: 'gzip' | 'deflate' | 'deflate-raw'): Promise<ArrayBuffer>;
|
|
278
|
+
/**
|
|
279
|
+
* 解压为文本
|
|
280
|
+
* @param compressedData
|
|
281
|
+
* @param format
|
|
282
|
+
*/
|
|
283
|
+
declare function decompressText(compressedData: ArrayBuffer | Uint8Array, format?: 'gzip' | 'deflate' | 'deflate-raw'): Promise<string>;
|
|
284
|
+
/**
|
|
285
|
+
* 压缩后转换为base64
|
|
286
|
+
* @param data
|
|
287
|
+
* @param format
|
|
288
|
+
*/
|
|
289
|
+
declare function compressToBase64(data: ArrayBuffer | Uint8Array, format?: 'gzip' | 'deflate' | 'deflate-raw'): Promise<string>;
|
|
290
|
+
/**
|
|
291
|
+
* 压缩文本为base64
|
|
292
|
+
* @param data
|
|
293
|
+
* @param format
|
|
294
|
+
*/
|
|
295
|
+
declare function compressTextToBase64(data: string, format?: 'gzip' | 'deflate' | 'deflate-raw'): Promise<string>;
|
|
296
|
+
/**
|
|
297
|
+
* 从base64中解压
|
|
298
|
+
* @param base64
|
|
299
|
+
* @param format
|
|
300
|
+
*/
|
|
301
|
+
declare function decompressFromBase64(base64: string, format?: 'gzip' | 'deflate' | 'deflate-raw'): Promise<ArrayBuffer>;
|
|
302
|
+
/**
|
|
303
|
+
* 从base64中解压为文本
|
|
304
|
+
* @param base64
|
|
305
|
+
* @param format
|
|
306
|
+
*/
|
|
307
|
+
declare function decompressTextFromBase64(base64: string, format?: 'gzip' | 'deflate' | 'deflate-raw'): Promise<string>;
|
|
308
|
+
|
|
309
|
+
type ValueCreator<T> = (key: string) => T;
|
|
310
|
+
declare class NamedWeakMap<T extends object = any> implements IDisposable {
|
|
311
|
+
valueCreator?: ValueCreator<T>;
|
|
312
|
+
private readonly objectRefs;
|
|
313
|
+
constructor(valueCreator?: ValueCreator<T>);
|
|
314
|
+
get(key: string): T | undefined;
|
|
315
|
+
set(key: string, value: T): void;
|
|
316
|
+
destroy(): void;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
interface IExportMeta {
|
|
320
|
+
readonly name: string;
|
|
321
|
+
description?: string;
|
|
322
|
+
extraData?: any;
|
|
323
|
+
}
|
|
324
|
+
interface IRecordMeta extends IExportMeta {
|
|
325
|
+
fields: Record<string, number>;
|
|
326
|
+
defaultValues?: Record<string, any>;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
interface IExportData<T = any, K extends keyof T = keyof T | any> extends IExportMeta {
|
|
330
|
+
fields?: Record<K, number>;
|
|
331
|
+
defaultValues?: Record<K, any>;
|
|
332
|
+
excludeFields?: K[];
|
|
333
|
+
data: Iterable<T> | AsyncIterable<T>;
|
|
334
|
+
}
|
|
335
|
+
interface IDataExportArg {
|
|
336
|
+
header: any;
|
|
337
|
+
exportData: IExportData[];
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
declare const exportSimpleData: (arg: IDataExportArg) => Promise<string>;
|
|
341
|
+
declare class SimpleDataExport implements AsyncIterable<string> {
|
|
342
|
+
private _arg?;
|
|
343
|
+
constructor(arg: IDataExportArg);
|
|
344
|
+
[Symbol.asyncIterator](): AsyncIterator<string>;
|
|
345
|
+
destroy(): void;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
type OnReadFn<T = any> = (name: string, page: T[], progress?: number, dataHeader?: IRecordMeta) => Promise<void> | void;
|
|
349
|
+
type OnNamedReadFn<T = any> = (page: T[], progress?: number, dataHeader?: IRecordMeta) => Promise<void> | void;
|
|
350
|
+
interface IReadRow<T> {
|
|
351
|
+
name: string;
|
|
352
|
+
data: T;
|
|
353
|
+
progress: number;
|
|
354
|
+
meta: IRecordMeta;
|
|
355
|
+
}
|
|
356
|
+
declare class SimpleDataReader {
|
|
357
|
+
private _textReader?;
|
|
358
|
+
constructor(dataOrReader: ITextReader | string);
|
|
359
|
+
getHeader(): any;
|
|
360
|
+
getSize(): number;
|
|
361
|
+
read<T>(targetName: string): IterableIterator<IReadRow<T>>;
|
|
362
|
+
read(): IterableIterator<IReadRow<any>>;
|
|
363
|
+
getAll<T = any>(targetName: string): T[];
|
|
364
|
+
pageRead(fn: OnReadFn, limit?: number): Promise<void>;
|
|
365
|
+
namedRead(fnRecord: Record<string, OnNamedReadFn>, limit?: number): Promise<void>;
|
|
366
|
+
destroy(): void;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
declare function base64ToBlob(base64: Base64DataURL | string, mimeType: string): Blob;
|
|
370
|
+
|
|
371
|
+
declare const enum BlobTypes {
|
|
372
|
+
/**
|
|
373
|
+
* 文本类型
|
|
374
|
+
*/
|
|
375
|
+
Text = 1,
|
|
376
|
+
/**
|
|
377
|
+
* 已编码的Base64URL
|
|
378
|
+
*/
|
|
379
|
+
Base64 = 2,
|
|
380
|
+
/**
|
|
381
|
+
* <img>对象,类型为 HTMLImageElement
|
|
382
|
+
*/
|
|
383
|
+
Image = 3,
|
|
384
|
+
/**
|
|
385
|
+
* 位图,类型为 ImageBitmap
|
|
386
|
+
*/
|
|
387
|
+
Bitmap = 4,
|
|
388
|
+
/**
|
|
389
|
+
* Svg,类型为HTMLUnknownElement
|
|
390
|
+
*/
|
|
391
|
+
Svg = 5,
|
|
392
|
+
/**
|
|
393
|
+
* Html,类型为Document
|
|
394
|
+
*/
|
|
395
|
+
Html = 6,
|
|
396
|
+
/**
|
|
397
|
+
* Xml,类型为XMLDocument
|
|
398
|
+
*/
|
|
399
|
+
Xml = 7,
|
|
400
|
+
/**
|
|
401
|
+
* Json,类型为any object
|
|
402
|
+
*/
|
|
403
|
+
Json = 8,
|
|
404
|
+
/**
|
|
405
|
+
* 本类库内置的简单数据类型,比JSON有更小的空间占用,更利于网络传输
|
|
406
|
+
* 类型为 SimpleDataReader
|
|
407
|
+
*/
|
|
408
|
+
SimpleData = 9,
|
|
409
|
+
/**
|
|
410
|
+
* 当为不支持的类型时,返回原Blob与可能的类型
|
|
411
|
+
*/
|
|
412
|
+
NotSupped = 10
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
type BlobResult = Blob | string | Base64DataURL | HTMLImageElement | ImageBitmap | HTMLUnknownElement | Document | XMLDocument;
|
|
416
|
+
interface IBlobPackage<T extends BlobResult = any> extends IExtensionMime {
|
|
417
|
+
type: BlobTypes;
|
|
418
|
+
blob: Blob;
|
|
419
|
+
result?: T;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
declare function readBlob(blob: Blob, encoding?: EncodingType): Promise<IBlobPackage>;
|
|
423
|
+
declare function readBlob(blob: Blob, type: BlobTypes.Base64): Promise<Base64DataURL>;
|
|
424
|
+
declare function readBlob(blob: Blob, type: BlobTypes.Image): Promise<HTMLImageElement>;
|
|
425
|
+
declare function readBlob(blob: Blob, type: BlobTypes.Bitmap): Promise<ImageBitmap>;
|
|
426
|
+
declare function readBlob(blob: Blob, type: BlobTypes.Svg): Promise<HTMLUnknownElement>;
|
|
427
|
+
declare function readBlob(blob: Blob, type: BlobTypes.Text, encoding?: EncodingType): Promise<string>;
|
|
428
|
+
declare function readBlob(blob: Blob, type: BlobTypes.Html, encoding?: EncodingType): Promise<Document>;
|
|
429
|
+
declare function readBlob(blob: Blob, type: BlobTypes.Xml, encoding?: EncodingType): Promise<XMLDocument>;
|
|
430
|
+
declare function readBlob(blob: Blob, type: BlobTypes.Json, encoding?: EncodingType): Promise<any>;
|
|
431
|
+
declare function readBlob(blob: Blob, type: BlobTypes.SimpleData, encoding?: EncodingType): Promise<SimpleDataReader>;
|
|
432
|
+
declare function readBlob(blob: Blob, type: BlobTypes, encoding: EncodingType): Promise<any>;
|
|
433
|
+
|
|
434
|
+
declare function readBlobData(blob: Blob, call: 'readAsText', encoding?: EncodingType): Promise<string>;
|
|
435
|
+
declare function readBlobData(blob: Blob, call: 'readAsDataURL'): Promise<string>;
|
|
436
|
+
declare function readBlobData(blob: Blob, call: 'readAsArrayBuffer'): Promise<ArrayBuffer>;
|
|
437
|
+
|
|
438
|
+
declare function miniToBlobType(miniType: MimeTypes): BlobTypes;
|
|
439
|
+
|
|
440
|
+
export { BlobTypes, FileMimeTypes, MimeTypes, NamedWeakMap, NetMimeTypes, SimpleDataExport, SimpleDataReader, base64ToBlob, compressData, compressText, compressTextToBase64, compressToBase64, decodeBase64, decompressData, decompressFromBase64, decompressText, decompressTextFromBase64, encodeBase64, exportSimpleData, getExtensionMime, miniToBlobType, parseMime, parseMimeExt, readBlob, readBlobData, supportsCompression };
|
|
441
|
+
export type { Base64DataURL, BlobResult, FullMimeType, IBlobPackage, IDataExportArg, IExportData, IExportMeta, IExtensionMime, IReadRow, IRecordMeta, OnNamedReadFn, OnReadFn, ValueCreator };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{invertRecordKv as a,isIterable as t,isAsyncIterable as e,joinAsyncIterable as i,isString as o,StringTextReader as n,copyObject as p,isNumber as c}from"gs-base";import{decode as s,encode as r}from"js-base64";var l,m,d,f,x,u;let g;(m=l||(l={})).TextPlain="text/plain",m.TextUTF8="text/plain;charset=UTF-8",m.TextUTF16BE="text/plain;charset=UTF-16BE",m.TextUTF16LE="text/plain;charset=UTF-16LE",m.HTML="text/html",m.CSS="text/css",m.JavaScript="text/javascript",m.XML="text/xml",m.JSON="application/json",m.CSV="text/csv",m.Markdown="text/markdown",m.LaTeX="application/x-latex",m.TSV="text/tab-separated-values",m.Bat="text/x-sh",m.SimpleData="text/x-simpledata",m.JPEG="image/jpeg",m.PNG="image/png",m.GIF="image/gif",m.SVG="image/svg+xml",m.WebP="image/webp",m.BMP="image/bmp",m.TIFF="image/tiff",m.HEIF="image/heif",m.HEIC="image/heic",m.ICO="image/x-icon",m.JPEG2000="image/jp2",m.AdobeXD="application/vnd.adobe.xd",m.PSD="image/vnd.adobe.photoshop",m.MP3="audio/mpeg",m.OGG="audio/ogg",m.WAV="audio/wav",m.AAC="audio/aac",m.FLAC="audio/flac",m.M4A="audio/x-m4a",m.AMR="audio/amr",m.WMA="audio/x-ms-wma",m.MP4="video/mp4",m.MPEG="video/mpeg",m.MP2T="video/MP2T",m.MPEGPS="video/MP1S",m.WebM="video/webm",m.OggVideo="video/ogg",m.QuickTime="video/quicktime",m.AVI="video/x-msvideo",m.MKV="video/x-matroska",m.MOV="video/quicktime",m.FLV="video/x-flv",m.WMV="video/x-ms-wmv",m.PDF="application/pdf",m.EXE="application/vnd.microsoft.portable-executable",m.MSI="application/x-msdownload",m.APK="application/vnd.android.package-archive",m.JAR="application/java-archive",m.DMG="application/x-apple-diskimage",m.ISO="application/x-iso9660-image",m.TTF="font/ttf",m.WOFF="font/woff",m.WOFF2="font/woff2",m.OTF="font/otf",m.EOT="application/vnd.ms-fontobject",m.SVGFont="font/svg+xml",m.DOC="application/msword",m.DOCX="application/vnd.openxmlformats-officedocument.wordprocessingml.document",m.XLS="application/vnd.ms-excel",m.XLSX="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",m.PPT="application/vnd.ms-powerpoint",m.PPTX="application/vnd.openxmlformats-officedocument.presentationml.presentation",m.ODT="application/vnd.oasis.opendocument.text",m.ODS="application/vnd.oasis.opendocument.spreadsheet",m.ODP="application/vnd.oasis.opendocument.presentation",m.RTF="application/rtf",m.Base64="application/base64",m.P7M="application/pkcs7-mime",m.P12="application/x-pkcs12",m.COM="application/x-msdos-program",m.DLL="application/x-msdownload",m.SYS="application/x-mswinexe",m.OLE="application/x-oleobject",m.OctetStream="application/octet-stream",m.UnknownBinary="application/x-unknown",m.Binary="application/x-binary",m.ZIP="application/zip",m.RAR="application/vnd.rar",m.GZIP="application/gzip",m.TAR="application/x-tar",m.BZIP2="application/x-bzip2",m.SEVEN_ZIP="application/x-7z-compressed",m.XZ="application/x-xz",m.GZ="application/x-gzip",m.TAR_GZ="application/gzip",m.LZ="application/x-lzip",m.LZH="application/x-lzh",m.Fbr="application/zip+fbr",m.M3U="audio/x-mpegurl",m.M3U8="application/x-mpegurl",m.PLS="audio/x-scpls",m.XSPF="application/xspf+xml",m.DPL="application/x-daumplaylist",(f=d||(d={})).MIME="message/rfc822",f.SMTP="application/smtp",f.HTTP="application/http",f.HTTPS="application/https",f.FTP="application/ftp",f.TCP="application/tcp",f.UDP="application/udp",f.JSONLD="application/ld+json",f.WebAssembly="application/wasm",f.SVGZ="image/svg+xml+gzip",f.MHTML="multipart/related",f.OGG="application/ogg",f.XAP="application/x-silverlight-app",f.WOFF="font/woff",f.WASM="application/wasm",f.WGT="application/widget",f.OctetStream="application/octet-stream",f.UnknownBinary="application/x-unknown",(u=x||(x={})).SimpleData="text/x-simpledata",u.Fbr="application/zip+fbr",u.PSD="image/vnd.adobe.photoshop",u.Bat="text/x-sh",u.TextPlain="text/plain",u.TextUTF8="text/plain;charset=UTF-8",u.TextUTF16LE="text/plain;charset=UTF-16LE",u.TextUTF16BE="text/plain;charset=UTF-16BE",u.HTML="text/html",u.CSS="text/css",u.JavaScript="text/javascript",u.XML="text/xml",u.JSON="application/json",u.CSV="text/csv",u.Markdown="text/markdown",u.RTF="application/rtf",u.LaTeX="application/x-latex",u.TSV="text/tab-separated-values",u.JPEG="image/jpeg",u.PNG="image/png",u.GIF="image/gif",u.SVG="image/svg+xml",u.WebP="image/webp",u.BMP="image/bmp",u.TIFF="image/tiff",u.HEIF="image/heif",u.HEIC="image/heic",u.ICO="image/x-icon",u.JPEG2000="image/jp2",u.MP3="audio/mpeg",u.OGG="audio/ogg",u.WAV="audio/wav",u.AAC="audio/aac",u.FLAC="audio/flac",u.M4A="audio/x-m4a",u.AMR="audio/amr",u.WMA="audio/x-ms-wma",u.MP4="video/mp4",u.MPEG="video/mpeg",u.MP2T="video/MP2T",u.MPEGPS="video/MP1S",u.WebM="video/webm",u.OggVideo="video/ogg",u.QuickTime="video/quicktime",u.AVI="video/x-msvideo",u.MKV="video/x-matroska",u.MOV="video/quicktime",u.FLV="video/x-flv",u.WMV="video/x-ms-wmv",u.PDF="application/pdf",u.ZIP="application/zip",u.RAR="application/vnd.rar",u.SEVEN_ZIP="application/x-7z-compressed",u.GZIP="application/gzip",u.TAR="application/x-tar",u.EXE="application/vnd.microsoft.portable-executable",u.MSI="application/x-msdownload",u.APK="application/vnd.android.package-archive",u.JAR="application/java-archive",u.DMG="application/x-apple-diskimage",u.ISO="application/x-iso9660-image",u.TTF="font/ttf",u.WOFF="font/woff",u.WOFF2="font/woff2",u.OTF="font/otf",u.EOT="application/vnd.ms-fontobject",u.SVGFont="font/svg+xml",u.DOC="application/msword",u.DOCX="application/vnd.openxmlformats-officedocument.wordprocessingml.document",u.AdobeXD="application/vnd.adobe.xd",u.XLS="application/vnd.ms-excel",u.XLSX="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",u.PPT="application/vnd.ms-powerpoint",u.PPTX="application/vnd.openxmlformats-officedocument.presentationml.presentation",u.ODT="application/vnd.oasis.opendocument.text",u.ODS="application/vnd.oasis.opendocument.spreadsheet",u.ODP="application/vnd.oasis.opendocument.presentation",u.Base64="application/base64",u.P7M="application/pkcs7-mime",u.P12="application/x-pkcs12",u.XZ="application/x-xz",u.BZIP2="application/x-bzip2",u.GZ="application/x-gzip",u.TAR_GZ="application/gzip",u.LZ="application/x-lzip",u.LZH="application/x-lzh",u.COM="application/x-msdos-program",u.DLL="application/x-msdownload",u.SYS="application/x-mswinexe",u.OLE="application/x-oleobject",u.Binary="application/x-binary",u.MIME="message/rfc822",u.SMTP="application/smtp",u.HTTP="application/http",u.HTTPS="application/https",u.FTP="application/ftp",u.TCP="application/tcp",u.UDP="application/udp",u.JSONLD="application/ld+json",u.WebAssembly="application/wasm",u.SVGZ="image/svg+xml+gzip",u.MHTML="multipart/related",u.XAP="application/x-silverlight-app",u.WASM="application/wasm",u.WGT="application/widget",u.OctetStream="application/octet-stream",u.UnknownBinary="application/x-unknown",u.M3U="audio/x-mpegurl",u.M3U8="application/x-mpegurl",u.PLS="audio/x-scpls",u.XSPF="application/xspf+xml",u.DPL="application/x-daumplaylist";const v=()=>g||(g={"text/x-simpledata":"txt","text/plain":"txt","text/html":"html","text/css":"css","text/javascript":"js","text/xml":"xml","application/json":"json","text/csv":"csv","text/markdown":"md","application/x-latex":"tex","text/tab-separated-values":"tsv","text/x-sh":"bat","image/jpeg":"jpg","image/png":"png","image/gif":"gif","image/svg+xml":"svg","image/webp":"webp","image/bmp":"bmp","image/tiff":"tiff","image/heif":"heif","image/heic":"heic","image/x-icon":"ico","image/jp2":"jp2","audio/mpeg":"mp3","audio/ogg":"ogg","audio/wav":"wav","audio/aac":"aac","audio/flac":"flac","audio/x-m4a":"m4a","audio/amr":"amr","audio/x-ms-wma":"wma","video/mp4":"mp4","video/webm":"webm","video/ogg":"ogg","video/quicktime":"mov","video/x-msvideo":"avi","video/x-matroska":"mkv","video/x-flv":"flv","video/x-ms-wmv":"wmv","application/pdf":"pdf","application/zip":"zip","application/vnd.rar":"rar","application/gzip":"gzip","application/x-tar":"tar","application/vnd.microsoft.portable-executable":"exe","application/x-msdownload":"msi","application/vnd.android.package-archive":"apk","application/java-archive":"jar","application/x-apple-diskimage":"dmg","application/x-iso9660-image":"iso","application/zip+fbr":"fbr","font/ttf":"ttf","font/woff":"woff","font/woff2":"woff2","font/otf":"otf","application/vnd.ms-fontobject":"eot","font/svg+xml":"svgfont","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","application/vnd.oasis.opendocument.text":"odt","application/vnd.oasis.opendocument.spreadsheet":"ods","application/vnd.oasis.opendocument.presentation":"odp","application/octet-stream":"exe","application/x-unknown":"unknown","audio/x-mpegurl":"m3u","application/x-mpegurl":"m3u8","audio/x-scpls":"pls","application/xspf+xml":"xspf","application/x-daumplaylist":"dpl"});let w;const h=/^\.?(\w+)(?:\/([0-9a-z-+.]+)\s*(?:;.*charset\s*=\s*([0-9a-z-]+).*)?)?$/i;function b(t){const e=h.exec(t);let i,o;return e?.[2]?(i=`${e[1]}/${e[2]}`,o=v()?.[i]||"unknown"):e?.[1]&&(o=e[1],i=(w||(w=a(v())),w)[o]||"application/x-unknown"),e?.[3]&&(i=`${i}; charset=${e[3]}`),{ext:o,mime:i}}let T;async function S(a,t,e=0){let i;return i=a instanceof Blob?new Uint8Array(await a.slice(e,t).arrayBuffer()):a instanceof ArrayBuffer?new Uint8Array(a.slice(e,t)):a.slice(e,t),i}async function P(a,t,e=0){return(new TextDecoder).decode(await S(a,t,e))}async function F(a){const t=await async function(a,t,e=0){return Array.from(await S(a,t,e)).map((a=>a.toString(16).padStart(2,"0"))).join("").toUpperCase()}(a,8);for(const[a,e]of T||(T=[["EFBBBF","text/plain;charset=UTF-8"],["FEFF","text/plain;charset=UTF-16BE"],["FFFE","text/plain;charset=UTF-16LE"],["FFD8FF","image/jpeg"],["89504E47","image/png"],["47494638","image/gif"],["49492A00","image/tiff"],["4D4D002A","image/tiff"],["424D","image/bmp"],["00000100","image/x-icon"],["38425053","image/vnd.adobe.photoshop"],["52494646","image/webp"],["57454250","image/webp"],["494433","audio/mpeg"],["4F676753","audio/ogg"],["57415645","audio/wav"],["664C6143","audio/flac"],["000001BA","video/MP1S"],["000001BA","video/mpeg"],["000001B3","video/mpeg"],["1A45DFA3","video/x-matroska"],["6674797069736F6D","video/mp4"],["0000001866747970","video/mp4"],["667479706d703432","video/mp4"],["47","video/MP2T"],["1A45DFA3","video/webm"],["504B0304","application/zip"],["52617221","application/vnd.rar"],["1F8B08","application/gzip"],["75737461","application/x-tar"],["425A68","application/x-bzip2"],["377ABCAF271C","application/x-7z-compressed"],["25504446","application/pdf"],["D0CF11E0A1B11AE1","application/msword"],["7B5C727466","application/rtf"],["4D5A","application/vnd.microsoft.portable-executable"],["FFD8FFE0","image/jpeg"],["MZ","application/octet-stream"]]))if(t.startsWith(a))return e}const y=[["word/","application/vnd.openxmlformats-officedocument.wordprocessingml.document"],["ppt/","application/vnd.openxmlformats-officedocument.presentationml.presentation"],["xl/","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],["@Uu","application/zip+fbr"],["mimetypeapplication/","application/vnd.adobe.xd"]];const A="//",M="SimpleData,",D=new RegExp(`^(${M})?(\\{.*\\}|\\[.*\\])$`,"i"),O=[[/^<(!DOCTYPE\s+)?html/i,"text/html"],[/^<svg/i,"image/svg+xml"],[/^<(\?xml|\w+)/i,"text/xml"],[/^[{\[]/i,"application/json"],[/^8BPS/i,"image/vnd.adobe.photoshop"],[/^@?(echo|chcp|set)/i,"text/x-sh"],[new RegExp(`^${M}`,"i"),"text/x-simpledata"],[/^DAUMPLAYLIST/i,"application/x-daumplaylist"]];async function z(a){const t=(await P(a,50)).trim();for(const[a,e]of O)if(a.test(t))return e}const E=/stream|unknown|binary|text|xml'/;async function j(a){const t=a.type||"";if(t&&!E.test(t))return t;let e=t?.includes("text/plain")?await z(a):"";if(e)return e;const i=await F(a);return/zip$/.test(i)?await async function(a){const t=await P(a,50,30);for(const[a,e]of y)if(t.includes(a))return e;return"application/zip"}(a):(e=!i||i.includes("text/plain")?await z(a):"",E.test(i)?e||t||i||void 0:e||i||t||void 0)}async function k(a){return b(`${await j(a)}`)}const B=s,L=r;function C(){return typeof CompressionStream<"u"&&typeof DecompressionStream<"u"}async function R(a,t="gzip"){const e=new CompressionStream(t),i=e.writable.getWriter();return i.write(a instanceof Uint8Array?a:new Uint8Array(a)),i.close(),await new Response(e.readable).arrayBuffer()}async function U(a,t="gzip"){const e=new DecompressionStream(t),i=e.writable.getWriter();i.write(a instanceof Uint8Array?a:new Uint8Array(a)),i.close();const o=e.readable;return await new Response(o).arrayBuffer()}async function G(a,t="gzip"){return await R((new TextEncoder).encode(a),t)}async function I(a,t="gzip"){return(new TextDecoder).decode(await U(a,t))}async function V(a,t="gzip"){return btoa(String.fromCharCode(...new Uint8Array(await R(a,t))))}async function W(a,t="gzip"){return btoa(String.fromCharCode(...new Uint8Array(await G(a,t))))}async function X(a,t="gzip"){const e=atob(a),i=e.length,o=new Uint8Array(i);for(let a=0;a<i;a++)o[a]=e.charCodeAt(a);return await U(o,t)}async function Z(a,t="gzip"){return(new TextDecoder).decode(await X(a,t))}class J{valueCreator;objectRefs={};constructor(a){this.valueCreator=a}get(a){let t=this.objectRefs[a]?.deref();return t||(this.valueCreator&&this.set(a,t=this.valueCreator(a)),t)}set(a,t){this.objectRefs[a]=new WeakRef(t)}destroy(){for(let a in this.objectRefs)this.objectRefs[a]?.deref()||delete this.objectRefs[a]}}async function H(a){if(a.fields)return _(a.fields,a.excludeFields);const i=await async function(a,i=30){const o=[];let n=1;if(t(a)){for(const t of a)if(o.push(t),++n>i)break}else if(e(a))for await(const t of a)if(o.push(t),++n>i)break;return o}(a.data),o={};let n,p=0;for(const a of i){const t=Object.keys(a).length;t>p&&(p=t,n=a)}p=0;for(const a in n)o[a]=p++;return _(o,a.excludeFields)}function N(a){return Object.entries(a).sort($)}function _(a,t){if(!t)return a;const e={},i=Object.entries(a).sort($);let o=0;for(const[a]of i)t.includes(a)||(e[a]=o++);return e}function $(a,t){return a[1]-t[1]}function q(a,t){const e=[];for(const[i]of a)e.push(t[i]);const i=JSON.stringify(e);return i.slice(1,i.length-1)}const K=a=>i(new Y(a));class Y{_arg;constructor(a){this._arg=a}async*[Symbol.asyncIterator](){const{header:a,exportData:i}=this._arg;yield`${M}${JSON.stringify(a)}`;for(const a of i){const i=await H(a),o=N(i),n={name:a.name,fields:i};if(a.description&&(n.description=a.description),a.extraData&&(n.extraData=a.extraData),a.defaultValues&&(n.defaultValues=a.defaultValues),yield`${A}${JSON.stringify(n)}`,t(a.data))for(const t of a.data)yield q(o,t);else if(e(a.data))for await(const t of a.data)yield q(o,t)}}destroy(){delete this._arg}}const Q=/^\s*$/;class aa{_textReader;constructor(a){o(a)?this._textReader=new n(a):this._textReader=a}getHeader(){const a=this._textReader.firstLine;return a&&D.exec(a)?.[2]||{}}getSize(){return this._textReader.size}*read(a){let t,e,i;for(const{data:o,progress:n}of this._textReader){if(Q.test(o))continue;if(o.startsWith(A)){if(i=JSON.parse(o.slice(2)),t&&t===a)return;t=i.name,e=[];for(const[a,t]of Object.entries(i.fields))e.push([a,Number(t)]);continue}if(!t||!e||a&&t!==a)continue;const c=JSON.parse(`[${o}]`),s=i?.defaultValues?p(i?.defaultValues):{};for(const[a,t]of e)s[a]=c[t];yield{name:t,data:s,progress:n,meta:i}}}getAll(a){const t=[];for(const{data:e}of this.read(a))t.push(e);return t}async pageRead(a,t=1e3){let e=[];const i=this._textReader.size;let o,n;for(const{name:i,data:p,progress:c,meta:s}of this.read())e.push(p),e.length>=t?(await a(i,e,c,s),e=[]):(o=i,n=s);e.length&&await a(o,e,i,n)}async namedRead(a,t=1e3){await this.pageRead((async(t,e,i,o)=>{t in a&&await a[t](e,i,o)}),t)}destroy(){try{this._textReader?.destroy?.()}finally{delete this._textReader}}}function ta(a,t){const e=a.indexOf(";base64,");e>-1&&(a=a.slice(e+8));const i=atob(a),o=i.length,n=new Uint8Array(o);for(let a=0;a<o;a++)n[a]=i.charCodeAt(a);return new Blob([n],{type:t})}var ea,ia;function oa(a,t,e){return new Promise(((i,o)=>{const n=new FileReader;n.onload=()=>{i(n.result)},n.onerror=o,n[t](a,e)}))}(ia=ea||(ea={}))[ia.Text=1]="Text",ia[ia.Base64=2]="Base64",ia[ia.Image=3]="Image",ia[ia.Bitmap=4]="Bitmap",ia[ia.Svg=5]="Svg",ia[ia.Html=6]="Html",ia[ia.Xml=7]="Xml",ia[ia.Json=8]="Json",ia[ia.SimpleData=9]="SimpleData",ia[ia.NotSupped=10]="NotSupped";const na=[1,6,5,7,8,9],pa=/<meta[^>]+charset\s*=\s*["']?([\w-]+)|^<\?xml[^>]+encoding\s*=\s*"?([\w-]+)/i;function ca(a,t){return(new globalThis.DOMParser).parseFromString(a,t)}const sa=[2,3];function ra(a){switch(a){case"text/plain":return 1;case"application/base64":return 2;case"image/jpeg":case"image/png":case"image/gif":case"image/webp":case"image/bmp":case"image/x-icon":return 3;case"image/svg+xml":return 5;case"text/html":return 6;case"text/xml":return 7;case"application/json":return 8;case"text/x-simpledata":return 9;default:return 10}}async function la(a,...t){let e=0;const i=c(t[e])?t[e++]:void 0,n=o(t[e])?t[e++]:void 0,p=!i&&await j(a),s=i||ra(p);let r;return 4===s?r=await globalThis.createImageBitmap(a):na.includes(s)?r=await async function(a,t,e){if(!e){const[,t,i]=pa.exec(await a.slice(0,1024).text())||[];e=t||i}const i=await oa(a,"readAsText",e);switch(t){case 5:return ca(i,"image/svg+xml").querySelector("svg");case 7:return ca(i,"text/xml");case 6:return ca(i,"text/html");case 9:return new aa(i);case 8:return JSON.parse(i);default:return i}}(a,s,n):sa.includes(s)&&(r=await function(a,t){return new Promise((async(e,i)=>{const o=await oa(a,"readAsDataURL");if(3===t){const a=new globalThis.Image;a.onload=()=>e(a),a.onerror=i,a.src=o}else e(o)}))}(a,s)),i&&10!==s?r:{...b(p),blob:a,type:s,result:r}}export{ea as BlobTypes,l as FileMimeTypes,x as MimeTypes,J as NamedWeakMap,d as NetMimeTypes,Y as SimpleDataExport,aa as SimpleDataReader,ta as base64ToBlob,R as compressData,G as compressText,W as compressTextToBase64,V as compressToBase64,B as decodeBase64,U as decompressData,X as decompressFromBase64,I as decompressText,Z as decompressTextFromBase64,L as encodeBase64,K as exportSimpleData,b as getExtensionMime,ra as miniToBlobType,j as parseMime,k as parseMimeExt,la as readBlob,oa as readBlobData,C as supportsCompression};
|
package/lib/index.web.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t,e,a,i,n,o;let p;(e=t||(t={})).TextPlain="text/plain",e.TextUTF8="text/plain;charset=UTF-8",e.TextUTF16BE="text/plain;charset=UTF-16BE",e.TextUTF16LE="text/plain;charset=UTF-16LE",e.HTML="text/html",e.CSS="text/css",e.JavaScript="text/javascript",e.XML="text/xml",e.JSON="application/json",e.CSV="text/csv",e.Markdown="text/markdown",e.LaTeX="application/x-latex",e.TSV="text/tab-separated-values",e.Bat="text/x-sh",e.SimpleData="text/x-simpledata",e.JPEG="image/jpeg",e.PNG="image/png",e.GIF="image/gif",e.SVG="image/svg+xml",e.WebP="image/webp",e.BMP="image/bmp",e.TIFF="image/tiff",e.HEIF="image/heif",e.HEIC="image/heic",e.ICO="image/x-icon",e.JPEG2000="image/jp2",e.AdobeXD="application/vnd.adobe.xd",e.PSD="image/vnd.adobe.photoshop",e.MP3="audio/mpeg",e.OGG="audio/ogg",e.WAV="audio/wav",e.AAC="audio/aac",e.FLAC="audio/flac",e.M4A="audio/x-m4a",e.AMR="audio/amr",e.WMA="audio/x-ms-wma",e.MP4="video/mp4",e.MPEG="video/mpeg",e.MP2T="video/MP2T",e.MPEGPS="video/MP1S",e.WebM="video/webm",e.OggVideo="video/ogg",e.QuickTime="video/quicktime",e.AVI="video/x-msvideo",e.MKV="video/x-matroska",e.MOV="video/quicktime",e.FLV="video/x-flv",e.WMV="video/x-ms-wmv",e.PDF="application/pdf",e.EXE="application/vnd.microsoft.portable-executable",e.MSI="application/x-msdownload",e.APK="application/vnd.android.package-archive",e.JAR="application/java-archive",e.DMG="application/x-apple-diskimage",e.ISO="application/x-iso9660-image",e.TTF="font/ttf",e.WOFF="font/woff",e.WOFF2="font/woff2",e.OTF="font/otf",e.EOT="application/vnd.ms-fontobject",e.SVGFont="font/svg+xml",e.DOC="application/msword",e.DOCX="application/vnd.openxmlformats-officedocument.wordprocessingml.document",e.XLS="application/vnd.ms-excel",e.XLSX="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",e.PPT="application/vnd.ms-powerpoint",e.PPTX="application/vnd.openxmlformats-officedocument.presentationml.presentation",e.ODT="application/vnd.oasis.opendocument.text",e.ODS="application/vnd.oasis.opendocument.spreadsheet",e.ODP="application/vnd.oasis.opendocument.presentation",e.RTF="application/rtf",e.Base64="application/base64",e.P7M="application/pkcs7-mime",e.P12="application/x-pkcs12",e.COM="application/x-msdos-program",e.DLL="application/x-msdownload",e.SYS="application/x-mswinexe",e.OLE="application/x-oleobject",e.OctetStream="application/octet-stream",e.UnknownBinary="application/x-unknown",e.Binary="application/x-binary",e.ZIP="application/zip",e.RAR="application/vnd.rar",e.GZIP="application/gzip",e.TAR="application/x-tar",e.BZIP2="application/x-bzip2",e.SEVEN_ZIP="application/x-7z-compressed",e.XZ="application/x-xz",e.GZ="application/x-gzip",e.TAR_GZ="application/gzip",e.LZ="application/x-lzip",e.LZH="application/x-lzh",e.Fbr="application/zip+fbr",e.M3U="audio/x-mpegurl",e.M3U8="application/x-mpegurl",e.PLS="audio/x-scpls",e.XSPF="application/xspf+xml",e.DPL="application/x-daumplaylist",(i=a||(a={})).MIME="message/rfc822",i.SMTP="application/smtp",i.HTTP="application/http",i.HTTPS="application/https",i.FTP="application/ftp",i.TCP="application/tcp",i.UDP="application/udp",i.JSONLD="application/ld+json",i.WebAssembly="application/wasm",i.SVGZ="image/svg+xml+gzip",i.MHTML="multipart/related",i.OGG="application/ogg",i.XAP="application/x-silverlight-app",i.WOFF="font/woff",i.WASM="application/wasm",i.WGT="application/widget",i.OctetStream="application/octet-stream",i.UnknownBinary="application/x-unknown",(o=n||(n={})).SimpleData="text/x-simpledata",o.Fbr="application/zip+fbr",o.PSD="image/vnd.adobe.photoshop",o.Bat="text/x-sh",o.TextPlain="text/plain",o.TextUTF8="text/plain;charset=UTF-8",o.TextUTF16LE="text/plain;charset=UTF-16LE",o.TextUTF16BE="text/plain;charset=UTF-16BE",o.HTML="text/html",o.CSS="text/css",o.JavaScript="text/javascript",o.XML="text/xml",o.JSON="application/json",o.CSV="text/csv",o.Markdown="text/markdown",o.RTF="application/rtf",o.LaTeX="application/x-latex",o.TSV="text/tab-separated-values",o.JPEG="image/jpeg",o.PNG="image/png",o.GIF="image/gif",o.SVG="image/svg+xml",o.WebP="image/webp",o.BMP="image/bmp",o.TIFF="image/tiff",o.HEIF="image/heif",o.HEIC="image/heic",o.ICO="image/x-icon",o.JPEG2000="image/jp2",o.MP3="audio/mpeg",o.OGG="audio/ogg",o.WAV="audio/wav",o.AAC="audio/aac",o.FLAC="audio/flac",o.M4A="audio/x-m4a",o.AMR="audio/amr",o.WMA="audio/x-ms-wma",o.MP4="video/mp4",o.MPEG="video/mpeg",o.MP2T="video/MP2T",o.MPEGPS="video/MP1S",o.WebM="video/webm",o.OggVideo="video/ogg",o.QuickTime="video/quicktime",o.AVI="video/x-msvideo",o.MKV="video/x-matroska",o.MOV="video/quicktime",o.FLV="video/x-flv",o.WMV="video/x-ms-wmv",o.PDF="application/pdf",o.ZIP="application/zip",o.RAR="application/vnd.rar",o.SEVEN_ZIP="application/x-7z-compressed",o.GZIP="application/gzip",o.TAR="application/x-tar",o.EXE="application/vnd.microsoft.portable-executable",o.MSI="application/x-msdownload",o.APK="application/vnd.android.package-archive",o.JAR="application/java-archive",o.DMG="application/x-apple-diskimage",o.ISO="application/x-iso9660-image",o.TTF="font/ttf",o.WOFF="font/woff",o.WOFF2="font/woff2",o.OTF="font/otf",o.EOT="application/vnd.ms-fontobject",o.SVGFont="font/svg+xml",o.DOC="application/msword",o.DOCX="application/vnd.openxmlformats-officedocument.wordprocessingml.document",o.AdobeXD="application/vnd.adobe.xd",o.XLS="application/vnd.ms-excel",o.XLSX="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",o.PPT="application/vnd.ms-powerpoint",o.PPTX="application/vnd.openxmlformats-officedocument.presentationml.presentation",o.ODT="application/vnd.oasis.opendocument.text",o.ODS="application/vnd.oasis.opendocument.spreadsheet",o.ODP="application/vnd.oasis.opendocument.presentation",o.Base64="application/base64",o.P7M="application/pkcs7-mime",o.P12="application/x-pkcs12",o.XZ="application/x-xz",o.BZIP2="application/x-bzip2",o.GZ="application/x-gzip",o.TAR_GZ="application/gzip",o.LZ="application/x-lzip",o.LZH="application/x-lzh",o.COM="application/x-msdos-program",o.DLL="application/x-msdownload",o.SYS="application/x-mswinexe",o.OLE="application/x-oleobject",o.Binary="application/x-binary",o.MIME="message/rfc822",o.SMTP="application/smtp",o.HTTP="application/http",o.HTTPS="application/https",o.FTP="application/ftp",o.TCP="application/tcp",o.UDP="application/udp",o.JSONLD="application/ld+json",o.WebAssembly="application/wasm",o.SVGZ="image/svg+xml+gzip",o.MHTML="multipart/related",o.XAP="application/x-silverlight-app",o.WASM="application/wasm",o.WGT="application/widget",o.OctetStream="application/octet-stream",o.UnknownBinary="application/x-unknown",o.M3U="audio/x-mpegurl",o.M3U8="application/x-mpegurl",o.PLS="audio/x-scpls",o.XSPF="application/xspf+xml",o.DPL="application/x-daumplaylist";const r=()=>p||(p={"text/x-simpledata":"txt","text/plain":"txt","text/html":"html","text/css":"css","text/javascript":"js","text/xml":"xml","application/json":"json","text/csv":"csv","text/markdown":"md","application/x-latex":"tex","text/tab-separated-values":"tsv","text/x-sh":"bat","image/jpeg":"jpg","image/png":"png","image/gif":"gif","image/svg+xml":"svg","image/webp":"webp","image/bmp":"bmp","image/tiff":"tiff","image/heif":"heif","image/heic":"heic","image/x-icon":"ico","image/jp2":"jp2","audio/mpeg":"mp3","audio/ogg":"ogg","audio/wav":"wav","audio/aac":"aac","audio/flac":"flac","audio/x-m4a":"m4a","audio/amr":"amr","audio/x-ms-wma":"wma","video/mp4":"mp4","video/webm":"webm","video/ogg":"ogg","video/quicktime":"mov","video/x-msvideo":"avi","video/x-matroska":"mkv","video/x-flv":"flv","video/x-ms-wmv":"wmv","application/pdf":"pdf","application/zip":"zip","application/vnd.rar":"rar","application/gzip":"gzip","application/x-tar":"tar","application/vnd.microsoft.portable-executable":"exe","application/x-msdownload":"msi","application/vnd.android.package-archive":"apk","application/java-archive":"jar","application/x-apple-diskimage":"dmg","application/x-iso9660-image":"iso","application/zip+fbr":"fbr","font/ttf":"ttf","font/woff":"woff","font/woff2":"woff2","font/otf":"otf","application/vnd.ms-fontobject":"eot","font/svg+xml":"svgfont","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","application/vnd.oasis.opendocument.text":"odt","application/vnd.oasis.opendocument.spreadsheet":"ods","application/vnd.oasis.opendocument.presentation":"odp","application/octet-stream":"exe","application/x-unknown":"unknown","audio/x-mpegurl":"m3u","application/x-mpegurl":"m3u8","audio/x-scpls":"pls","application/xspf+xml":"xspf","application/x-daumplaylist":"dpl"});function c(t){return t instanceof Function||"function"==typeof t}function s(t){return"string"==typeof t||t instanceof String}function l(t){return null!=t&&c(t[Symbol.iterator])}function d(t){return null!=t&&c(t[Symbol.asyncIterator])}function m(t){if("object"!=typeof t||null===t||t instanceof Date||t instanceof Function||t instanceof RegExp||typeof Element<"u"&&t instanceof Element)return t;if(t instanceof Set){const e=new Set;for(const a of t)e.add(m(a));return e}if(t instanceof Map){const e=new Map;for(const[a,i]of t)e.set(m(a),m(i));return e}if(Array.isArray(t)){const e=[];for(const a of t)e.push(m(a));return e}const e={};for(const[a,i]of Object.entries(t))e[a]=m(i);return e}var f=Object.defineProperty,u=(t,e,a)=>{return o=a,(n="symbol"!=typeof e?e+"":e)in(i=t)?f(i,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[n]=o,a;var i,n,o};class x{constructor(t,e="\n",a=!0){u(this,"lineBreakChar"),u(this,"contentIncludeFirstLine"),u(this,"size"),u(this,"_raw"),u(this,"firstLineEnd",0),this._raw=t,this.lineBreakChar=e,this.contentIncludeFirstLine=a,this.size=t.length}get firstLine(){return 0===this.firstLineEnd&&(this.firstLineEnd=this._raw.indexOf(this.lineBreakChar),-1===this.firstLineEnd&&(this.firstLineEnd=this._raw.length)),this._raw.slice(0,this.firstLineEnd)}*[Symbol.iterator](){const{_raw:t,lineBreakChar:e}=this,a=t.length,i=e.length;let n=this.firstLine&&!this.contentIncludeFirstLine?this.firstLineEnd+i:0;for(;n<a;){const o=t.indexOf(e,n);if(-1===o){yield{data:t.slice(n),progress:a};break}yield{data:t.slice(n,o),progress:o},n=o+i}}destroy(){delete this._raw}}let g;const h=/^\.?(\w+)(?:\/([0-9a-z-+.]+)\s*(?:;.*charset\s*=\s*([0-9a-z-]+).*)?)?$/i;function v(t){const e=h.exec(t);let a,i;return e?.[2]?(a=`${e[1]}/${e[2]}`,i=r()?.[a]||"unknown"):e?.[1]&&(i=e[1],a=(g||(g=function(t){const e={};for(const a in t)t.hasOwnProperty(a)&&(e[t[a]]=a);return e}(r())),g)[i]||"application/x-unknown"),e?.[3]&&(a=`${a}; charset=${e[3]}`),{ext:i,mime:a}}let w;async function b(t,e,a=0){let i;return i=t instanceof Blob?new Uint8Array(await t.slice(a,e).arrayBuffer()):t instanceof ArrayBuffer?new Uint8Array(t.slice(a,e)):t.slice(a,e),i}async function y(t,e,a=0){return(new TextDecoder).decode(await b(t,e,a))}async function A(t){const e=await async function(t,e,a=0){return Array.from(await b(t,e,a)).map((t=>t.toString(16).padStart(2,"0"))).join("").toUpperCase()}(t,8);for(const[t,a]of w||(w=[["EFBBBF","text/plain;charset=UTF-8"],["FEFF","text/plain;charset=UTF-16BE"],["FFFE","text/plain;charset=UTF-16LE"],["FFD8FF","image/jpeg"],["89504E47","image/png"],["47494638","image/gif"],["49492A00","image/tiff"],["4D4D002A","image/tiff"],["424D","image/bmp"],["00000100","image/x-icon"],["38425053","image/vnd.adobe.photoshop"],["52494646","image/webp"],["57454250","image/webp"],["494433","audio/mpeg"],["4F676753","audio/ogg"],["57415645","audio/wav"],["664C6143","audio/flac"],["000001BA","video/MP1S"],["000001BA","video/mpeg"],["000001B3","video/mpeg"],["1A45DFA3","video/x-matroska"],["6674797069736F6D","video/mp4"],["0000001866747970","video/mp4"],["667479706d703432","video/mp4"],["47","video/MP2T"],["1A45DFA3","video/webm"],["504B0304","application/zip"],["52617221","application/vnd.rar"],["1F8B08","application/gzip"],["75737461","application/x-tar"],["425A68","application/x-bzip2"],["377ABCAF271C","application/x-7z-compressed"],["25504446","application/pdf"],["D0CF11E0A1B11AE1","application/msword"],["7B5C727466","application/rtf"],["4D5A","application/vnd.microsoft.portable-executable"],["FFD8FFE0","image/jpeg"],["MZ","application/octet-stream"]]))if(e.startsWith(t))return a}const F=[["word/","application/vnd.openxmlformats-officedocument.wordprocessingml.document"],["ppt/","application/vnd.openxmlformats-officedocument.presentationml.presentation"],["xl/","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],["@Uu","application/zip+fbr"],["mimetypeapplication/","application/vnd.adobe.xd"]];const S="//",T="SimpleData,",P=new RegExp(`^(${T})?(\\{.*\\}|\\[.*\\])$`,"i"),M=[[/^<(!DOCTYPE\s+)?html/i,"text/html"],[/^<svg/i,"image/svg+xml"],[/^<(\?xml|\w+)/i,"text/xml"],[/^[{\[]/i,"application/json"],[/^8BPS/i,"image/vnd.adobe.photoshop"],[/^@?(echo|chcp|set)/i,"text/x-sh"],[new RegExp(`^${T}`,"i"),"text/x-simpledata"],[/^DAUMPLAYLIST/i,"application/x-daumplaylist"]];async function E(t){const e=(await y(t,50)).trim();for(const[t,a]of M)if(t.test(e))return a}const C=/stream|unknown|binary|text|xml'/;async function D(t){const e=t.type||"";if(e&&!C.test(e))return e;let a=e?.includes("text/plain")?await E(t):"";if(a)return a;const i=await A(t);return/zip$/.test(i)?await async function(t){const e=await y(t,50,30);for(const[t,a]of F)if(e.includes(t))return a;return"application/zip"}(t):(a=!i||i.includes("text/plain")?await E(t):"",C.test(i)?a||e||i||void 0:a||i||e||void 0)}async function O(t){return v(`${await D(t)}`)}const B="function"==typeof Buffer,z="function"==typeof TextDecoder?new TextDecoder:void 0,L="function"==typeof TextEncoder?new TextEncoder:void 0,j=Array.prototype.slice.call("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="),k=(()=>{let t={};return j.forEach(((e,a)=>t[e]=a)),t})(),U=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,R=String.fromCharCode.bind(String),I="function"==typeof Uint8Array.from?Uint8Array.from.bind(Uint8Array):t=>new Uint8Array(Array.prototype.slice.call(t,0)),G=t=>t.replace(/[^A-Za-z0-9\+\/]/g,""),V="function"==typeof btoa?t=>btoa(t):B?t=>Buffer.from(t,"binary").toString("base64"):t=>{let e,a,i,n,o="";const p=t.length%3;for(let p=0;p<t.length;){if((a=t.charCodeAt(p++))>255||(i=t.charCodeAt(p++))>255||(n=t.charCodeAt(p++))>255)throw new TypeError("invalid character found");e=a<<16|i<<8|n,o+=j[e>>18&63]+j[e>>12&63]+j[e>>6&63]+j[63&e]}return p?o.slice(0,p-3)+"===".substring(p):o},W=B?t=>Buffer.from(t).toString("base64"):t=>{let e=[];for(let a=0,i=t.length;a<i;a+=4096)e.push(R.apply(null,t.subarray(a,a+4096)));return V(e.join(""))},X=t=>{if(t.length<2)return(e=t.charCodeAt(0))<128?t:e<2048?R(192|e>>>6)+R(128|63&e):R(224|e>>>12&15)+R(128|e>>>6&63)+R(128|63&e);var e=65536+1024*(t.charCodeAt(0)-55296)+(t.charCodeAt(1)-56320);return R(240|e>>>18&7)+R(128|e>>>12&63)+R(128|e>>>6&63)+R(128|63&e)},Z=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,_=B?t=>Buffer.from(t,"utf8").toString("base64"):L?t=>W(L.encode(t)):t=>V(t.replace(Z,X)),J=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g,N=t=>{switch(t.length){case 4:var e=((7&t.charCodeAt(0))<<18|(63&t.charCodeAt(1))<<12|(63&t.charCodeAt(2))<<6|63&t.charCodeAt(3))-65536;return R(55296+(e>>>10))+R(56320+(1023&e));case 3:return R((15&t.charCodeAt(0))<<12|(63&t.charCodeAt(1))<<6|63&t.charCodeAt(2));default:return R((31&t.charCodeAt(0))<<6|63&t.charCodeAt(1))}},H="function"==typeof atob?t=>atob(G(t)):B?t=>Buffer.from(t,"base64").toString("binary"):t=>{if(t=t.replace(/\s+/g,""),!U.test(t))throw new TypeError("malformed base64.");t+="==".slice(2-(3&t.length));let e,a,i,n=[];for(let o=0;o<t.length;)e=k[t.charAt(o++)]<<18|k[t.charAt(o++)]<<12|(a=k[t.charAt(o++)])<<6|(i=k[t.charAt(o++)]),64===a?n.push(R(e>>16&255)):64===i?n.push(R(e>>16&255,e>>8&255)):n.push(R(e>>16&255,e>>8&255,255&e));return n.join("")},$=B?t=>I(Buffer.from(t,"base64")):t=>I(H(t).split("").map((t=>t.charCodeAt(0)))),q=B?t=>Buffer.from(t,"base64").toString("utf8"):z?t=>z.decode($(t)):t=>H(t).replace(J,N),K=t=>q(G(t.replace(/[-_]/g,(t=>"-"==t?"+":"/")))),Y=(t,e=!1)=>e?(t=>t.replace(/=/g,"").replace(/[+\/]/g,(t=>"+"==t?"-":"_")))(_(t)):_(t);function Q(){return typeof CompressionStream<"u"&&typeof DecompressionStream<"u"}async function tt(t,e="gzip"){const a=new CompressionStream(e),i=a.writable.getWriter();return i.write(t instanceof Uint8Array?t:new Uint8Array(t)),i.close(),await new Response(a.readable).arrayBuffer()}async function et(t,e="gzip"){const a=new DecompressionStream(e),i=a.writable.getWriter();i.write(t instanceof Uint8Array?t:new Uint8Array(t)),i.close();const n=a.readable;return await new Response(n).arrayBuffer()}async function at(t,e="gzip"){return await tt((new TextEncoder).encode(t),e)}async function it(t,e="gzip"){return(new TextDecoder).decode(await et(t,e))}async function nt(t,e="gzip"){return btoa(String.fromCharCode(...new Uint8Array(await tt(t,e))))}async function ot(t,e="gzip"){return btoa(String.fromCharCode(...new Uint8Array(await at(t,e))))}async function pt(t,e="gzip"){const a=atob(t),i=a.length,n=new Uint8Array(i);for(let t=0;t<i;t++)n[t]=a.charCodeAt(t);return await et(n,e)}async function rt(t,e="gzip"){return(new TextDecoder).decode(await pt(t,e))}class ct{valueCreator;objectRefs={};constructor(t){this.valueCreator=t}get(t){let e=this.objectRefs[t]?.deref();return e||(this.valueCreator&&this.set(t,e=this.valueCreator(t)),e)}set(t,e){this.objectRefs[t]=new WeakRef(e)}destroy(){for(let t in this.objectRefs)this.objectRefs[t]?.deref()||delete this.objectRefs[t]}}async function st(t){if(t.fields)return dt(t.fields,t.excludeFields);const e=await async function(t,e=30){const a=[];let i=1;if(l(t)){for(const n of t)if(a.push(n),++i>e)break}else if(d(t))for await(const n of t)if(a.push(n),++i>e)break;return a}(t.data),a={};let i,n=0;for(const t of e){const e=Object.keys(t).length;e>n&&(n=e,i=t)}n=0;for(const t in i)a[t]=n++;return dt(a,t.excludeFields)}function lt(t){return Object.entries(t).sort(mt)}function dt(t,e){if(!e)return t;const a={},i=Object.entries(t).sort(mt);let n=0;for(const[t]of i)e.includes(t)||(a[t]=n++);return a}function mt(t,e){return t[1]-e[1]}function ft(t,e){const a=[];for(const[i]of t)a.push(e[i]);const i=JSON.stringify(a);return i.slice(1,i.length-1)}const ut=t=>async function(t,e="\n"){const a=[];for await(const e of t)a.push(e);return a.join(e)}(new xt(t));class xt{_arg;constructor(t){this._arg=t}async*[Symbol.asyncIterator](){const{header:t,exportData:e}=this._arg;yield`${T}${JSON.stringify(t)}`;for(const t of e){const e=await st(t),a=lt(e),i={name:t.name,fields:e};if(t.description&&(i.description=t.description),t.extraData&&(i.extraData=t.extraData),t.defaultValues&&(i.defaultValues=t.defaultValues),yield`${S}${JSON.stringify(i)}`,l(t.data))for(const e of t.data)yield ft(a,e);else if(d(t.data))for await(const e of t.data)yield ft(a,e)}}destroy(){delete this._arg}}const gt=/^\s*$/;class ht{_textReader;constructor(t){s(t)?this._textReader=new x(t):this._textReader=t}getHeader(){const t=this._textReader.firstLine;return t&&P.exec(t)?.[2]||{}}getSize(){return this._textReader.size}*read(t){let e,a,i;for(const{data:n,progress:o}of this._textReader){if(gt.test(n))continue;if(n.startsWith(S)){if(i=JSON.parse(n.slice(2)),e&&e===t)return;e=i.name,a=[];for(const[t,e]of Object.entries(i.fields))a.push([t,Number(e)]);continue}if(!e||!a||t&&e!==t)continue;const p=JSON.parse(`[${n}]`),r=i?.defaultValues?m(i?.defaultValues):{};for(const[t,e]of a)r[t]=p[e];yield{name:e,data:r,progress:o,meta:i}}}getAll(t){const e=[];for(const{data:a}of this.read(t))e.push(a);return e}async pageRead(t,e=1e3){let a=[];const i=this._textReader.size;let n,o;for(const{name:i,data:p,progress:r,meta:c}of this.read())a.push(p),a.length>=e?(await t(i,a,r,c),a=[]):(n=i,o=c);a.length&&await t(n,a,i,o)}async namedRead(t,e=1e3){await this.pageRead((async(e,a,i,n)=>{e in t&&await t[e](a,i,n)}),e)}destroy(){try{this._textReader?.destroy?.()}finally{delete this._textReader}}}function vt(t,e){const a=t.indexOf(";base64,");a>-1&&(t=t.slice(a+8));const i=atob(t),n=i.length,o=new Uint8Array(n);for(let t=0;t<n;t++)o[t]=i.charCodeAt(t);return new Blob([o],{type:e})}var wt,bt;function yt(t,e,a){return new Promise(((i,n)=>{const o=new FileReader;o.onload=()=>{i(o.result)},o.onerror=n,o[e](t,a)}))}(bt=wt||(wt={}))[bt.Text=1]="Text",bt[bt.Base64=2]="Base64",bt[bt.Image=3]="Image",bt[bt.Bitmap=4]="Bitmap",bt[bt.Svg=5]="Svg",bt[bt.Html=6]="Html",bt[bt.Xml=7]="Xml",bt[bt.Json=8]="Json",bt[bt.SimpleData=9]="SimpleData",bt[bt.NotSupped=10]="NotSupped";const At=[1,6,5,7,8,9],Ft=/<meta[^>]+charset\s*=\s*["']?([\w-]+)|^<\?xml[^>]+encoding\s*=\s*"?([\w-]+)/i;function St(t,e){return(new globalThis.DOMParser).parseFromString(t,e)}const Tt=[2,3];function Pt(t){switch(t){case"text/plain":return 1;case"application/base64":return 2;case"image/jpeg":case"image/png":case"image/gif":case"image/webp":case"image/bmp":case"image/x-icon":return 3;case"image/svg+xml":return 5;case"text/html":return 6;case"text/xml":return 7;case"application/json":return 8;case"text/x-simpledata":return 9;default:return 10}}async function Mt(t,...e){let a=0;const i="number"==typeof(r=e[a])||r instanceof Number?e[a++]:void 0,n=s(e[a])?e[a++]:void 0,o=!i&&await D(t),p=i||Pt(o);var r;let c;return 4===p?c=await globalThis.createImageBitmap(t):At.includes(p)?c=await async function(t,e,a){if(!a){const[,e,i]=Ft.exec(await t.slice(0,1024).text())||[];a=e||i}const i=await yt(t,"readAsText",a);switch(e){case 5:return St(i,"image/svg+xml").querySelector("svg");case 7:return St(i,"text/xml");case 6:return St(i,"text/html");case 9:return new ht(i);case 8:return JSON.parse(i);default:return i}}(t,p,n):Tt.includes(p)&&(c=await function(t,e){return new Promise((async(a,i)=>{const n=await yt(t,"readAsDataURL");if(3===e){const t=new globalThis.Image;t.onload=()=>a(t),t.onerror=i,t.src=n}else a(n)}))}(t,p)),i&&10!==p?c:{...v(o),blob:t,type:p,result:c}}export{wt as BlobTypes,t as FileMimeTypes,n as MimeTypes,ct as NamedWeakMap,a as NetMimeTypes,xt as SimpleDataExport,ht as SimpleDataReader,vt as base64ToBlob,tt as compressData,at as compressText,ot as compressTextToBase64,nt as compressToBase64,K as decodeBase64,et as decompressData,pt as decompressFromBase64,it as decompressText,rt as decompressTextFromBase64,Y as encodeBase64,ut as exportSimpleData,v as getExtensionMime,Pt as miniToBlobType,D as parseMime,O as parseMimeExt,Mt as readBlob,yt as readBlobData,Q as supportsCompression};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gs-data",
|
|
3
|
+
"version": "0.1.10",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "lib/index.cjs",
|
|
6
|
+
"module": "lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
"import": "./lib/index.js",
|
|
9
|
+
"require": "./lib/index.cjs"
|
|
10
|
+
},
|
|
11
|
+
"types": "lib/index.d.ts",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"gs-base": "latest",
|
|
14
|
+
"js-base64": "^3.7.8"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"file-type",
|
|
18
|
+
"web-file-type",
|
|
19
|
+
"browser-file-type",
|
|
20
|
+
"file read/write",
|
|
21
|
+
"mime type",
|
|
22
|
+
"file extension",
|
|
23
|
+
"文件类型分析",
|
|
24
|
+
"文件读写"
|
|
25
|
+
],
|
|
26
|
+
"homepage": "https://gitee.com/grain-sand/grain-sand-data",
|
|
27
|
+
"preferred-homepages": [
|
|
28
|
+
"https://github.com/grain-sand/grain-sand-data"
|
|
29
|
+
],
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/grain-sand/grain-sand-data"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
}
|
|
38
|
+
}
|