@mdgate/zip 0.1.0
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.md +29 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/to-markdown.d.ts +6 -0
- package/dist/zip.d.ts +2 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @mdgate/zip
|
|
2
|
+
|
|
3
|
+
Convert generic ZIP archives by converting each member. Outputs GitHub-Flavored Markdown. Works in
|
|
4
|
+
Node, Edge, and browsers. No native addons.
|
|
5
|
+
|
|
6
|
+
Handles: `.zip`, `.zipx`, `.jar` (not Office/ODF/EPUB/iWork packages — those win at sniff 2)
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { toMarkdown } from '@mdgate/zip';
|
|
12
|
+
|
|
13
|
+
const markdown = await toMarkdown(bytes);
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Compose with other converters so members are converted by format:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { create } from '@mdgate/core';
|
|
20
|
+
import { csv } from '@mdgate/csv';
|
|
21
|
+
import { zip } from '@mdgate/zip';
|
|
22
|
+
|
|
23
|
+
const convert = create([zip(), csv()]);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Without a nested `convert`, member names are listed as a bullet list.
|
|
27
|
+
|
|
28
|
+
Part of [mdgate converters](https://github.com/mdgate/converters); install
|
|
29
|
+
`@mdgate/converters` for every format at once.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{create as k}from"@mdgate/core";import{detectZipDoc as N,hasOleMagic as z,Package as F}from"@mdgate/containers";import{ConvertError as J}from"@mdgate/core";import{documentToMarkdown as $,emptyDocument as P,heading as D,plain as B}from"@mdgate/document";import{fileExtension as Z}from"@mdgate/utils";var j=new Set(["zip","zipx","jar"]);function H(){return{id:"zip",sniff(q,A){if(N(q)!==void 0)return 0;if(X(q))return 2;if(A?.path!==void 0&&j.has(Z(A.path)??""))return 1;return 0},convert(q,A){O(q);let G;try{G=F.open(q)}catch(Q){throw u(Q)}let L=T(G);if(A?.convert===void 0)return{markdown:$(x(L))};return S(G,L,A.convert)}}}function O(q){if(X(q))return;if(C(q))throw J.unsupported("pdf");if(z(q))throw J.unsupported("ole");throw J.unsupported("zip")}async function S(q,A,G){let L=[];for(let Q of A){let R=M(Q),Y;try{Y=q.part(Q)}catch(I){if(I instanceof J&&I.isFatal())throw I;if(U(I))throw J.encrypted();L.push(V(R,_(K(I))));continue}if(Y===void 0){L.push(V(R,_(`missing required part: ${Q}`)));continue}try{let I=await G(Y,{path:Q});L.push(V(R,I.trimEnd()))}catch(I){if(I instanceof J&&I.isFatal())throw I;L.push(V(R,_(K(I))))}}return{markdown:f(L)}}function T(q){let A=[];for(let G of q.partNames()){if(G.endsWith("/"))continue;if(w(G))continue;A.push(G)}return A}function w(q){for(let A of q.split("/"))if(A==="__MACOSX")return!0;return!1}function x(q){if(q.length===0)return P();return{blocks:[{type:"list",list:{marker:"bullet",start:1,items:q.map((A)=>({blocks:[{type:"paragraph",inlines:[B(A)]}],checked:void 0,markerLabel:void 0}))}}],notes:[],assets:[]}}function M(q){return $({blocks:[D(2,[B(q)])],notes:[],assets:[]}).trimEnd()}function _(q){return $({blocks:[{type:"paragraph",inlines:[B(`could not convert: ${q}`)]}],notes:[],assets:[]}).trimEnd()}function V(q,A){return A.length===0?q:`${q}
|
|
2
|
+
|
|
3
|
+
${A}`}function f(q){let A=q.filter((G)=>G.length>0);return A.length===0?"":`${A.join(`
|
|
4
|
+
|
|
5
|
+
`)}
|
|
6
|
+
`}function K(q){return q instanceof Error?q.message:String(q)}function u(q){if(q instanceof J){if(q.code==="encrypted")return q;if(U(q))return J.encrypted();return q}let A=q instanceof Error?q.message:String(q);if(W(A))return J.encrypted();return J.malformed(`not a readable zip archive: ${A}`)}function U(q){if(q instanceof J&&q.code==="encrypted")return!0;let A=q instanceof J?q.detail??"":"",G=q instanceof Error?`${q.message} ${A}`:String(q);return W(G)}function W(q){let A=q.toLowerCase();return A.includes("encrypted")||A.includes("password")}function X(q){return q.length>=4&&q[0]===80&&q[1]===75&&q[2]===3&&q[3]===4}function C(q){return q.length>=5&&q[0]===37&&q[1]===80&&q[2]===68&&q[3]===70&&q[4]===45}var h=k([H()]);function g(q,A){return h(q,A)}export{H as zip,g as toMarkdown};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ConvertHint } from '@mdgate/core';
|
|
2
|
+
/**
|
|
3
|
+
* Convert a single file's bytes to Markdown with the zip converter.
|
|
4
|
+
* `hint.path` is only a sniff hint; it is never read from disk.
|
|
5
|
+
*/
|
|
6
|
+
export declare function toMarkdown(bytes: Uint8Array, hint?: ConvertHint): Promise<string>;
|
package/dist/zip.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mdgate/zip",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "mdgate generic ZIP converter",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/**/*.js",
|
|
18
|
+
"dist/**/*.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "bun ../../scripts/build-package.ts",
|
|
22
|
+
"prepublishOnly": "bun run build"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@mdgate/containers": "0.1.0",
|
|
26
|
+
"@mdgate/core": "0.1.3",
|
|
27
|
+
"@mdgate/document": "0.1.0",
|
|
28
|
+
"@mdgate/utils": "0.1.2"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=20"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"mdgate",
|
|
38
|
+
"markdown",
|
|
39
|
+
"zip"
|
|
40
|
+
]
|
|
41
|
+
}
|