From 8559100e996ebb69a21bab2c19d52a46981de6a5 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 30 Aug 2021 17:42:23 +0200 Subject: [PATCH 1/3] fix:! do not wrap array inputs without path --- package-lock.json | 164 +++++++++++++++--------------- src/pack/index.ts | 5 + test/pack/index.browser.test.ts | 109 ++++++++++++++++++-- test/pack/index.node.test.ts | 4 +- test/unpack/index.browser.test.ts | 38 +++++-- 5 files changed, 219 insertions(+), 101 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9ddf30c..d0e735e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -821,9 +821,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "16.7.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.7.2.tgz", - "integrity": "sha512-TbG4TOx9hng8FKxaVrCisdaxKxqEwJ3zwHoCWXZ0Jw6mnvTInpaB99/2Cy4+XxpXtjNv9/TgfGSvZFyfV/t8Fw==" + "version": "16.7.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.7.6.tgz", + "integrity": "sha512-VESVNFoa/ahYA62xnLBjo5ur6gPsgEE5cNRy8SrdnkZ2nwJSW0kJ4ufbFr2zuU9ALtHM8juY53VcRoTA7htXSg==" }, "node_modules/@types/normalize-package-data": { "version": "2.4.1", @@ -1796,9 +1796,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.3.818", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.818.tgz", - "integrity": "sha512-c/Z9gIr+jDZAR9q+mn40hEc1NharBT+8ejkarjbCDnBNFviI6hvcC5j2ezkAXru//bTnQp5n6iPi0JA83Tla1Q==", + "version": "1.3.822", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.822.tgz", + "integrity": "sha512-k7jG5oYYHxF4jx6PcqwHX3JVME/OjzolqOZiIogi9xtsfsmTjTdie4x88OakYFPEa8euciTgCCzvVNwvmjHb1Q==", "dev": true }, "node_modules/emoji-regex": { @@ -2053,9 +2053,9 @@ } }, "node_modules/find-cache-dir": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.1.tgz", - "integrity": "sha512-t2GDMt3oGC/v+BMwzmllWDuJF/xcDtE5j/fCGbqDD7OLuJkj0cfh1YSA5VKPvwMeLFLNDBkwOKZ2X85jGLVftQ==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.2.tgz", + "integrity": "sha512-wXZV5emFEjrridIgED11OoUKLxiYjAcqot/NJdAkOhlJ+vGzwhOAfcG5OX1jP+S0PcjEn8bdMJv+g2jwQ3Onig==", "dev": true, "dependencies": { "commondir": "^1.0.1", @@ -2630,9 +2630,9 @@ } }, "node_modules/ipfs-unixfs": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/ipfs-unixfs/-/ipfs-unixfs-6.0.4.tgz", - "integrity": "sha512-5ARPcTtDGgFK6jPYWAitgDTxIjEcrqz3+ReIPuFZCcekglt2jS8osoZYSLNtpGDtjGevQtaJAgce+BQDY3ymBA==", + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs/-/ipfs-unixfs-6.0.5.tgz", + "integrity": "sha512-D8Z3EsegLxOBc2L8oMyZw/FRUDQG0ZZAaBRfzMrRsGnj7RFI7OlV1hU54aMeDxFYFviKNnUdsyEFI2zUWmgGvw==", "dependencies": { "err-code": "^3.0.1", "protobufjs": "^6.10.2" @@ -2643,9 +2643,9 @@ } }, "node_modules/ipfs-unixfs-exporter": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/ipfs-unixfs-exporter/-/ipfs-unixfs-exporter-7.0.4.tgz", - "integrity": "sha512-5G6IIAaZlLuK7lFW17u57INnSkqaaZbIqXQWPqKJUncmK3Sq7+m3Yl9IzyP5gsLTM/H/AIPD7xbTqIeuIz+PHQ==", + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs-exporter/-/ipfs-unixfs-exporter-7.0.5.tgz", + "integrity": "sha512-H/fBcBHO4kMivj2JyqwVmp90JIxKEsRpgkyifkZxmslttcTgivrOM3s7xeLuj6EkchkqyHS9+wurdv83WFOFpQ==", "dependencies": { "@ipld/dag-cbor": "^6.0.4", "@ipld/dag-pb": "^2.0.2", @@ -2653,7 +2653,7 @@ "err-code": "^3.0.1", "hamt-sharding": "^2.0.0", "interface-blockstore": "^1.0.0", - "ipfs-unixfs": "^6.0.4", + "ipfs-unixfs": "^6.0.5", "it-last": "^1.0.5", "multiformats": "^9.4.2", "uint8arrays": "^3.0.0" @@ -2664,9 +2664,9 @@ } }, "node_modules/ipfs-unixfs-importer": { - "version": "9.0.4", - "resolved": "https://registry.npmjs.org/ipfs-unixfs-importer/-/ipfs-unixfs-importer-9.0.4.tgz", - "integrity": "sha512-RCl3f6/5zRT6716UYuRZET5iWafi9gvRPmgHhWE0Pmco74T2h/VPNHCgj6Noo85fVCNG5KsGBL38uzONO85MNA==", + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs-importer/-/ipfs-unixfs-importer-9.0.5.tgz", + "integrity": "sha512-+Xxqu7WKC/cFd/IP5bCPw4E29CybU0k/exxNJCCn/QDrSm+o25Dz4IFCLc9jXvffi9Za8gCMywZFeM2HbB5Dyg==", "dependencies": { "@ipld/dag-pb": "^2.0.2", "@multiformats/murmur3": "^1.0.3", @@ -2674,7 +2674,7 @@ "err-code": "^3.0.1", "hamt-sharding": "^2.0.0", "interface-blockstore": "^1.0.0", - "ipfs-unixfs": "^6.0.4", + "ipfs-unixfs": "^6.0.5", "it-all": "^1.0.5", "it-batch": "^1.0.8", "it-first": "^1.0.6", @@ -2690,9 +2690,9 @@ } }, "node_modules/ipfs-utils": { - "version": "8.1.5", - "resolved": "https://registry.npmjs.org/ipfs-utils/-/ipfs-utils-8.1.5.tgz", - "integrity": "sha512-qjERTUy0iXPw5LRPA1OQLzYPjdYb7JQenihYaE0L+yA4NMoC9qhGVrYUqU8yaV0Iu+zk7i6BxoNwg8beWsqjbg==", + "version": "8.1.6", + "resolved": "https://registry.npmjs.org/ipfs-utils/-/ipfs-utils-8.1.6.tgz", + "integrity": "sha512-V/cwb6113DrDhrjDTWImA6+zmJbpdbUkxdxmEQO7it8ykV76bBmzU1ZXSM0QR0qxGy9VW8dkUlPAC2K10VgSmw==", "dependencies": { "abort-controller": "^3.0.0", "any-signal": "^2.1.0", @@ -2707,7 +2707,7 @@ "nanoid": "^3.1.20", "native-abort-controller": "^1.0.3", "native-fetch": "^3.0.0", - "node-fetch": "npm:@achingbrain/node-fetch@^2.6.4", + "node-fetch": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz", "react-native-fetch-api": "^2.0.0", "stream-to-it": "^0.2.2" } @@ -3659,9 +3659,9 @@ } }, "node_modules/mocha": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.0.tgz", - "integrity": "sha512-Kjg/XxYOFFUi0h/FwMOeb6RoroiZ+P1yOfya6NK7h3dNhahrJx1r2XIT3ge4ZQvJM86mdjNA+W5phqRQh7DwCg==", + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.1.tgz", + "integrity": "sha512-0wE74YMgOkCgBUj8VyIDwmLUjTsS13WV1Pg7l0SHea2qzZzlq7MDnfbPsHKcELBRk3+izEVkRofjmClpycudCA==", "dev": true, "dependencies": { "@ungap/promise-all-settled": "1.1.2", @@ -3830,6 +3830,7 @@ "version": "2.6.7", "resolved": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz", "integrity": "sha512-iTASGs+HTFK5E4ZqcMsHmeJ4zodyq8L38lZV33jwqcBJYoUt3HjN4+ot+O9/0b+ke8ddE7UgOtVuZN/OkV19/g==", + "license": "MIT", "engines": { "node": "4.x || >=6.0.0" } @@ -5236,12 +5237,12 @@ } }, "node_modules/sirv": { - "version": "1.0.16", - "resolved": "https://registry.npmjs.org/sirv/-/sirv-1.0.16.tgz", - "integrity": "sha512-x56DISeIgSUGVJrQS3mwu+UvtnzHenKDFBQL+UlAswxwk9b2Cpc0KGVvftoIJZgweOOXbMZzyXFYgVElOuSI1Q==", + "version": "1.0.17", + "resolved": "https://registry.npmjs.org/sirv/-/sirv-1.0.17.tgz", + "integrity": "sha512-qx9go5yraB7ekT7bCMqUHJ5jEaOC/GXBxUWv+jeWnb7WzHUFdcQPGWk7YmAwFBaQBrogpuSqd/azbC2lZRqqmw==", "dev": true, "dependencies": { - "@polka/url": "^1.0.0-next.19", + "@polka/url": "^1.0.0-next.20", "mime": "^2.3.1", "totalist": "^1.0.0" }, @@ -5250,9 +5251,9 @@ } }, "node_modules/sirv/node_modules/@polka/url": { - "version": "1.0.0-next.19", - "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.19.tgz", - "integrity": "sha512-kHR9OHwP9WLpyC0i/WCAQCgf5hXkR9C+/21qxmrn+YwRlDRnBlqrcrFpXxhJTA9LDHJWa/FjoO2LJ12q8iWlEQ==", + "version": "1.0.0-next.20", + "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.20.tgz", + "integrity": "sha512-88p7+M0QGxKpmnkfXjS4V26AnoC/eiqZutE8GLdaI5X12NY75bXSdTY9NkmYb2Xyk1O+MmkuO6Frmsj84V6I8Q==", "dev": true }, "node_modules/slash": { @@ -5962,9 +5963,9 @@ } }, "node_modules/typescript": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", - "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.2.tgz", + "integrity": "sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -6266,9 +6267,9 @@ } }, "node_modules/ws": { - "version": "7.5.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.3.tgz", - "integrity": "sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.4.tgz", + "integrity": "sha512-zP9z6GXm6zC27YtspwH99T3qTG7bBFv2VIkeHstMLrLlDJuzA7tQ5ls3OJ1hOGGCzTQPniNJoHXIAOS0Jljohg==", "dev": true, "engines": { "node": ">=8.3.0" @@ -7085,9 +7086,9 @@ "dev": true }, "@types/node": { - "version": "16.7.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.7.2.tgz", - "integrity": "sha512-TbG4TOx9hng8FKxaVrCisdaxKxqEwJ3zwHoCWXZ0Jw6mnvTInpaB99/2Cy4+XxpXtjNv9/TgfGSvZFyfV/t8Fw==" + "version": "16.7.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.7.6.tgz", + "integrity": "sha512-VESVNFoa/ahYA62xnLBjo5ur6gPsgEE5cNRy8SrdnkZ2nwJSW0kJ4ufbFr2zuU9ALtHM8juY53VcRoTA7htXSg==" }, "@types/normalize-package-data": { "version": "2.4.1", @@ -7836,9 +7837,9 @@ } }, "electron-to-chromium": { - "version": "1.3.818", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.818.tgz", - "integrity": "sha512-c/Z9gIr+jDZAR9q+mn40hEc1NharBT+8ejkarjbCDnBNFviI6hvcC5j2ezkAXru//bTnQp5n6iPi0JA83Tla1Q==", + "version": "1.3.822", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.822.tgz", + "integrity": "sha512-k7jG5oYYHxF4jx6PcqwHX3JVME/OjzolqOZiIogi9xtsfsmTjTdie4x88OakYFPEa8euciTgCCzvVNwvmjHb1Q==", "dev": true }, "emoji-regex": { @@ -8040,9 +8041,9 @@ } }, "find-cache-dir": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.1.tgz", - "integrity": "sha512-t2GDMt3oGC/v+BMwzmllWDuJF/xcDtE5j/fCGbqDD7OLuJkj0cfh1YSA5VKPvwMeLFLNDBkwOKZ2X85jGLVftQ==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.2.tgz", + "integrity": "sha512-wXZV5emFEjrridIgED11OoUKLxiYjAcqot/NJdAkOhlJ+vGzwhOAfcG5OX1jP+S0PcjEn8bdMJv+g2jwQ3Onig==", "dev": true, "requires": { "commondir": "^1.0.1", @@ -8457,18 +8458,18 @@ } }, "ipfs-unixfs": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/ipfs-unixfs/-/ipfs-unixfs-6.0.4.tgz", - "integrity": "sha512-5ARPcTtDGgFK6jPYWAitgDTxIjEcrqz3+ReIPuFZCcekglt2jS8osoZYSLNtpGDtjGevQtaJAgce+BQDY3ymBA==", + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs/-/ipfs-unixfs-6.0.5.tgz", + "integrity": "sha512-D8Z3EsegLxOBc2L8oMyZw/FRUDQG0ZZAaBRfzMrRsGnj7RFI7OlV1hU54aMeDxFYFviKNnUdsyEFI2zUWmgGvw==", "requires": { "err-code": "^3.0.1", "protobufjs": "^6.10.2" } }, "ipfs-unixfs-exporter": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/ipfs-unixfs-exporter/-/ipfs-unixfs-exporter-7.0.4.tgz", - "integrity": "sha512-5G6IIAaZlLuK7lFW17u57INnSkqaaZbIqXQWPqKJUncmK3Sq7+m3Yl9IzyP5gsLTM/H/AIPD7xbTqIeuIz+PHQ==", + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs-exporter/-/ipfs-unixfs-exporter-7.0.5.tgz", + "integrity": "sha512-H/fBcBHO4kMivj2JyqwVmp90JIxKEsRpgkyifkZxmslttcTgivrOM3s7xeLuj6EkchkqyHS9+wurdv83WFOFpQ==", "requires": { "@ipld/dag-cbor": "^6.0.4", "@ipld/dag-pb": "^2.0.2", @@ -8476,16 +8477,16 @@ "err-code": "^3.0.1", "hamt-sharding": "^2.0.0", "interface-blockstore": "^1.0.0", - "ipfs-unixfs": "^6.0.4", + "ipfs-unixfs": "^6.0.5", "it-last": "^1.0.5", "multiformats": "^9.4.2", "uint8arrays": "^3.0.0" } }, "ipfs-unixfs-importer": { - "version": "9.0.4", - "resolved": "https://registry.npmjs.org/ipfs-unixfs-importer/-/ipfs-unixfs-importer-9.0.4.tgz", - "integrity": "sha512-RCl3f6/5zRT6716UYuRZET5iWafi9gvRPmgHhWE0Pmco74T2h/VPNHCgj6Noo85fVCNG5KsGBL38uzONO85MNA==", + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs-importer/-/ipfs-unixfs-importer-9.0.5.tgz", + "integrity": "sha512-+Xxqu7WKC/cFd/IP5bCPw4E29CybU0k/exxNJCCn/QDrSm+o25Dz4IFCLc9jXvffi9Za8gCMywZFeM2HbB5Dyg==", "requires": { "@ipld/dag-pb": "^2.0.2", "@multiformats/murmur3": "^1.0.3", @@ -8493,7 +8494,7 @@ "err-code": "^3.0.1", "hamt-sharding": "^2.0.0", "interface-blockstore": "^1.0.0", - "ipfs-unixfs": "^6.0.4", + "ipfs-unixfs": "^6.0.5", "it-all": "^1.0.5", "it-batch": "^1.0.8", "it-first": "^1.0.6", @@ -8505,9 +8506,9 @@ } }, "ipfs-utils": { - "version": "8.1.5", - "resolved": "https://registry.npmjs.org/ipfs-utils/-/ipfs-utils-8.1.5.tgz", - "integrity": "sha512-qjERTUy0iXPw5LRPA1OQLzYPjdYb7JQenihYaE0L+yA4NMoC9qhGVrYUqU8yaV0Iu+zk7i6BxoNwg8beWsqjbg==", + "version": "8.1.6", + "resolved": "https://registry.npmjs.org/ipfs-utils/-/ipfs-utils-8.1.6.tgz", + "integrity": "sha512-V/cwb6113DrDhrjDTWImA6+zmJbpdbUkxdxmEQO7it8ykV76bBmzU1ZXSM0QR0qxGy9VW8dkUlPAC2K10VgSmw==", "requires": { "abort-controller": "^3.0.0", "any-signal": "^2.1.0", @@ -8522,7 +8523,7 @@ "nanoid": "^3.1.20", "native-abort-controller": "^1.0.3", "native-fetch": "^3.0.0", - "node-fetch": "npm:@achingbrain/node-fetch@^2.6.4", + "node-fetch": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz", "react-native-fetch-api": "^2.0.0", "stream-to-it": "^0.2.2" } @@ -9220,9 +9221,9 @@ } }, "mocha": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.0.tgz", - "integrity": "sha512-Kjg/XxYOFFUi0h/FwMOeb6RoroiZ+P1yOfya6NK7h3dNhahrJx1r2XIT3ge4ZQvJM86mdjNA+W5phqRQh7DwCg==", + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.1.tgz", + "integrity": "sha512-0wE74YMgOkCgBUj8VyIDwmLUjTsS13WV1Pg7l0SHea2qzZzlq7MDnfbPsHKcELBRk3+izEVkRofjmClpycudCA==", "dev": true, "requires": { "@ungap/promise-all-settled": "1.1.2", @@ -9347,8 +9348,7 @@ } }, "node-fetch": { - "version": "npm:@achingbrain/node-fetch@2.6.7", - "resolved": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz", + "version": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz", "integrity": "sha512-iTASGs+HTFK5E4ZqcMsHmeJ4zodyq8L38lZV33jwqcBJYoUt3HjN4+ot+O9/0b+ke8ddE7UgOtVuZN/OkV19/g==" }, "node-preload": { @@ -10387,20 +10387,20 @@ } }, "sirv": { - "version": "1.0.16", - "resolved": "https://registry.npmjs.org/sirv/-/sirv-1.0.16.tgz", - "integrity": "sha512-x56DISeIgSUGVJrQS3mwu+UvtnzHenKDFBQL+UlAswxwk9b2Cpc0KGVvftoIJZgweOOXbMZzyXFYgVElOuSI1Q==", + "version": "1.0.17", + "resolved": "https://registry.npmjs.org/sirv/-/sirv-1.0.17.tgz", + "integrity": "sha512-qx9go5yraB7ekT7bCMqUHJ5jEaOC/GXBxUWv+jeWnb7WzHUFdcQPGWk7YmAwFBaQBrogpuSqd/azbC2lZRqqmw==", "dev": true, "requires": { - "@polka/url": "^1.0.0-next.19", + "@polka/url": "^1.0.0-next.20", "mime": "^2.3.1", "totalist": "^1.0.0" }, "dependencies": { "@polka/url": { - "version": "1.0.0-next.19", - "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.19.tgz", - "integrity": "sha512-kHR9OHwP9WLpyC0i/WCAQCgf5hXkR9C+/21qxmrn+YwRlDRnBlqrcrFpXxhJTA9LDHJWa/FjoO2LJ12q8iWlEQ==", + "version": "1.0.0-next.20", + "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.20.tgz", + "integrity": "sha512-88p7+M0QGxKpmnkfXjS4V26AnoC/eiqZutE8GLdaI5X12NY75bXSdTY9NkmYb2Xyk1O+MmkuO6Frmsj84V6I8Q==", "dev": true } } @@ -10938,9 +10938,9 @@ } }, "typescript": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", - "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.2.tgz", + "integrity": "sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==", "dev": true }, "uint8arrays": { @@ -11182,9 +11182,9 @@ } }, "ws": { - "version": "7.5.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.3.tgz", - "integrity": "sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.4.tgz", + "integrity": "sha512-zP9z6GXm6zC27YtspwH99T3qTG7bBFv2VIkeHstMLrLlDJuzA7tQ5ls3OJ1hOGGCzTQPniNJoHXIAOS0Jljohg==", "dev": true, "requires": {} }, diff --git a/src/pack/index.ts b/src/pack/index.ts index d6535d4..8199c45 100644 --- a/src/pack/index.ts +++ b/src/pack/index.ts @@ -28,6 +28,11 @@ export async function pack ({ input, blockstore: userBlockstore, hasher, maxChun throw new Error('missing input file(s)') } + // Disable wrap with directory if we receive byte arrays as input with no path + if (Array.isArray(input) && input.filter((i) => !i.path).length) { + wrapWithDirectory = false + } + const blockstore = userBlockstore ? userBlockstore : new MemoryBlockStore() // Consume the source diff --git a/test/pack/index.browser.test.ts b/test/pack/index.browser.test.ts index f9f6153..99e1b32 100644 --- a/test/pack/index.browser.test.ts +++ b/test/pack/index.browser.test.ts @@ -9,9 +9,12 @@ import { MemoryBlockStore } from '../../src/blockstore/memory' describe('pack', () => { [MemoryBlockStore].map((Blockstore) => { describe(`with ${Blockstore.name}`, () => { - it('with iterable input', async () => { + it('with iterable input of one file', async () => { const { root, out } = await pack({ - input: [new Uint8Array([21, 31])], + input: [{ + path: 'a.txt', + content: new Uint8Array([21, 31]) + }], blockstore: new Blockstore() }) @@ -20,13 +23,94 @@ describe('pack', () => { carParts.push(part) } - expect(root.toString()).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(root.toString()).to.eql('bafybeiglo54z2343qksf253l2xtsik3n4kdguwtfayhhtn36btqrnlwrsu') expect(carParts.length).to.eql(7) }) - it('can pack with custom unixfs importer options', async () => { + it('with iterable input of many files', async () => { + const { root, out } = await pack({ + input: [ + { + path: 'a.txt', + content: new Uint8Array([21, 31]) + }, + { + path: 'b.txt', + content: new Uint8Array([22, 32]) + } + ], + blockstore: new Blockstore() + }) + + const carParts = [] + for await (const part of out) { + carParts.push(part) + } + + expect(root.toString()).to.eql('bafybeifvinv2j25rn2dndgrpgeo5bfrknvjpqowoxw7msr4iyub6izyr5a') + expect(carParts.length).to.eql(10) + }) + + it('can pack with an array input without path (defaults to wrapWithDirectory to false)', async () => { + const { root, out } = await pack({ + input: [{ + content: new Uint8Array([21, 31]) + }], + blockstore: new Blockstore() + }) + + const carParts = [] + for await (const part of out) { + carParts.push(part) + } + + expect(root.toString()).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') + expect(carParts.length).to.eql(4) + }) + + it('can pack with an array input without path in one of the entries (defaults to wrapWithDirectory to false)', async () => { + const { root, out } = await pack({ + input: [{ + path: 'a.txt', + content: new Uint8Array([21, 31]) + }, + { + content: new Uint8Array([22, 32]) + } + ], + blockstore: new Blockstore() + }) + + const carParts = [] + for await (const part of out) { + carParts.push(part) + } + + expect(root.toString()).to.eql('bafkreihdoh3xvolzxa4aa3snjjnhkgigs4rbbsj2qdax5kfbtlfewdmx5q') + expect(carParts.length).to.eql(7) + }) + + it('can pack with an uint8array input without path (defaults to wrapWithDirectory to false)', async () => { const { root, out } = await pack({ input: [new Uint8Array([21, 31])], + blockstore: new Blockstore() + }) + + const carParts = [] + for await (const part of out) { + carParts.push(part) + } + + expect(root.toString()).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') + expect(carParts.length).to.eql(4) + }) + + it('can pack with custom unixfs importer options', async () => { + const { root, out } = await pack({ + input: [{ + path: 'a.txt', + content: new Uint8Array([21, 31]) + }], blockstore: new Blockstore(), hasher: sha512, maxChunkSize: 1048576, @@ -45,11 +129,14 @@ describe('pack', () => { it('returns a car blob', async () => { const { root, car } = await packToBlob({ - input: [new Uint8Array([21, 31])], + input: [{ + path: 'a.txt', + content: new Uint8Array([21, 31]) + }], blockstore: new Blockstore() }) - expect(root.toString()).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(root.toString()).to.eql('bafybeiglo54z2343qksf253l2xtsik3n4kdguwtfayhhtn36btqrnlwrsu') }) it('pack does not close provided blockstore', async () => { @@ -57,7 +144,10 @@ describe('pack', () => { const spy = sinon.spy(blockstore, 'close') await pack({ - input: [new Uint8Array([21, 31])], + input: [{ + path: 'a.txt', + content: new Uint8Array([21, 31]) + }], blockstore }) @@ -70,7 +160,10 @@ describe('pack', () => { const spy = sinon.spy(blockstore, 'close') await packToBlob({ - input: [new Uint8Array([21, 31])], + input: [{ + path: 'a.txt', + content: new Uint8Array([21, 31]) + }], blockstore }) diff --git a/test/pack/index.node.test.ts b/test/pack/index.node.test.ts index f44b8ee..d1a14e6 100644 --- a/test/pack/index.node.test.ts +++ b/test/pack/index.node.test.ts @@ -197,7 +197,7 @@ describe('pack', () => { }) expect(car).to.exist - expect(root.toString()).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(root.toString()).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') await blockstore.close() }) @@ -211,7 +211,7 @@ describe('pack', () => { }) expect(car).to.exist - expect(root.toString()).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(root.toString()).to.eql('bafkreiadsbmmn4waznesyuz3bjgrj33xzqhxrk6mz3ksq7meugrachh3qe') await blockstore.close() }) diff --git a/test/unpack/index.browser.test.ts b/test/unpack/index.browser.test.ts index d79ad41..7eb378b 100644 --- a/test/unpack/index.browser.test.ts +++ b/test/unpack/index.browser.test.ts @@ -12,21 +12,29 @@ import { IdbBlockStore } from '../../src/blockstore/idb' describe('unpack', () => { it('with CarReader input', async () => { const { out } = await pack({ - input: [new Uint8Array([21, 31])], + input: [{ + path: 'a.txt', + content: new Uint8Array([21, 31]) + }], blockstore: new MemoryBlockStore() }) let bytes = new Uint8Array([]) + let carParts = [] for await (const part of out) { + carParts.push(part) bytes = concat([bytes, new Uint8Array(part)]) } const carReader = await CarReader.fromBytes(bytes) const files = await all(unpack(carReader)) - expect(files.length).to.eql(1) + expect(files.length).to.eql(2) expect(files[0].type).to.eql('directory') - expect(files[0].name).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(files[0].name).to.eql('bafybeiglo54z2343qksf253l2xtsik3n4kdguwtfayhhtn36btqrnlwrsu') + expect(files[1].type).to.eql('raw') + expect(files[1].name).to.eql('a.txt') + expect(files[1].path).to.eql('bafybeiglo54z2343qksf253l2xtsik3n4kdguwtfayhhtn36btqrnlwrsu/a.txt') }) }) @@ -35,17 +43,26 @@ describe('unpackStream', () => { describe(`with ${Blockstore.name}`, () => { it('with iterable input', async () => { const { out } = await pack({ - input: [new Uint8Array([21, 31])], + input: [{ + path: 'a.txt', + content: new Uint8Array([21, 31]) + }], blockstore: new MemoryBlockStore() }) const files = await all(unpackStream(out, {blockstore: new Blockstore()})) - expect(files.length).to.eql(1) + expect(files.length).to.eql(2) expect(files[0].type).to.eql('directory') - expect(files[0].name).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(files[0].name).to.eql('bafybeiglo54z2343qksf253l2xtsik3n4kdguwtfayhhtn36btqrnlwrsu') + expect(files[1].type).to.eql('raw') + expect(files[1].name).to.eql('a.txt') + expect(files[1].path).to.eql('bafybeiglo54z2343qksf253l2xtsik3n4kdguwtfayhhtn36btqrnlwrsu/a.txt') }) it('with readablestream input', async () => { const { out } = await pack({ - input: [new Uint8Array([21, 31])], + input: [{ + path: 'a.txt', + content: new Uint8Array([21, 31]) + }], blockstore: new MemoryBlockStore() }) const stream = new ReadableStream({ @@ -57,9 +74,12 @@ describe('unpackStream', () => { } }) const files = await all(unpackStream(stream, {blockstore: new Blockstore()})) - expect(files.length).to.eql(1) + expect(files.length).to.eql(2) expect(files[0].type).to.eql('directory') - expect(files[0].name).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(files[0].name).to.eql('bafybeiglo54z2343qksf253l2xtsik3n4kdguwtfayhhtn36btqrnlwrsu') + expect(files[1].type).to.eql('raw') + expect(files[1].name).to.eql('a.txt') + expect(files[1].path).to.eql('bafybeiglo54z2343qksf253l2xtsik3n4kdguwtfayhhtn36btqrnlwrsu/a.txt') }) }) }) From 0c048cd978046222b1fbc4bb0bac1c24d729f6be Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 2 Sep 2021 11:47:05 +0200 Subject: [PATCH 2/3] fix:! do not wrap with directory by default --- README.md | 17 ++- package-lock.json | 224 +++++++++++++++--------------- src/pack/constants.ts | 2 +- test/pack/index.browser.test.ts | 24 +++- test/pack/index.node.test.ts | 14 +- test/unpack/index.browser.test.ts | 12 +- 6 files changed, 163 insertions(+), 130 deletions(-) diff --git a/README.md b/README.md index ac60d38..7782e83 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ import { MemoryBlockStore } from 'ipfs-car/blockstore/memory' // You can also us const { root, out } = await pack({ input: [new Uint8Array([21, 31, 41])], blockstore: new MemoryBlockStore(), - wrapWithDirectory: true // Wraps input into a directory. Defaults to `true` + wrapWithDirectory: false // Wraps inputs with paths into a directory. Defaults to `false` maxChunkSize: 262144 // The maximum block size in bytes. Defaults to `262144`. Max safe value is < 1048576 (1MiB) }) @@ -117,6 +117,21 @@ for await (const part of out) { } ``` +When using `wrapWithDirectory` functionality, a path for the files needs to be provided, in order to have DAG links properly created. See the example as follows: + +```js +import { pack } from 'ipfs-car/pack' +import { MemoryBlockStore } from 'ipfs-car/blockstore/memory' // You can also use the `level-blockstore` module + +const { root, out } = await pack({ + input: [{ + path: 'file.txt', + content: new Uint8Array([21, 31, 41]) + }], + wrapWithDirectory: true +}) +``` + ### `ipfs-car/pack/blob` Takes an [ImportCandidateStream](https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-core-types/src/utils.d.ts#L27) and writes it to a [Blob](https://github.com/web-std/io/tree/main/blob). diff --git a/package-lock.json b/package-lock.json index 9ddf30c..3fe236b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -499,9 +499,9 @@ } }, "node_modules/@ipld/dag-cbor": { - "version": "6.0.9", - "resolved": "https://registry.npmjs.org/@ipld/dag-cbor/-/dag-cbor-6.0.9.tgz", - "integrity": "sha512-Kj8K8z2YMhupPJMHAn3jSVgGl/V7gT3Eki1dCE4bVhbli+vHS6lLObZXAcrTXMMHHYFmkSoOFdvwoYu5AU7lBA==", + "version": "6.0.10", + "resolved": "https://registry.npmjs.org/@ipld/dag-cbor/-/dag-cbor-6.0.10.tgz", + "integrity": "sha512-dGinQkyDKQ5vkgX8JxbXBX2fl2GB+cn6u6a6cm/pTub1WeB/PMoDJ9pU7VSBvHUtGO+ZoueeQ06TgEnO+t9esg==", "dependencies": { "cborg": "^1.2.1", "multiformats": "^9.0.0" @@ -821,9 +821,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "16.7.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.7.2.tgz", - "integrity": "sha512-TbG4TOx9hng8FKxaVrCisdaxKxqEwJ3zwHoCWXZ0Jw6mnvTInpaB99/2Cy4+XxpXtjNv9/TgfGSvZFyfV/t8Fw==" + "version": "16.7.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.7.10.tgz", + "integrity": "sha512-S63Dlv4zIPb8x6MMTgDq5WWRJQe56iBEY0O3SOFA9JrRienkOVDXSXBjjJw6HTNQYSE2JI6GMCR6LVbIMHJVvA==" }, "node_modules/@types/normalize-package-data": { "version": "2.4.1", @@ -1087,9 +1087,9 @@ } }, "node_modules/available-typed-arrays": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.4.tgz", - "integrity": "sha512-SA5mXJWrId1TaQjfxUYghbqQ/hYioKmLJvPJyDuYRtXXenFNMjj4hSSt1Cf1xsuXSXrtxrVC5Ot4eU6cOtBDdA==", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", + "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==", "engines": { "node": ">= 0.4" }, @@ -1796,9 +1796,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.3.818", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.818.tgz", - "integrity": "sha512-c/Z9gIr+jDZAR9q+mn40hEc1NharBT+8ejkarjbCDnBNFviI6hvcC5j2ezkAXru//bTnQp5n6iPi0JA83Tla1Q==", + "version": "1.3.827", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.827.tgz", + "integrity": "sha512-ye+4uQOY/jbjRutMcE/EmOcNwUeo1qo9aKL2tPyb09cU3lmxNeyDF4RWiemmkknW+p29h7dyDqy02higTxc9/A==", "dev": true }, "node_modules/emoji-regex": { @@ -2053,9 +2053,9 @@ } }, "node_modules/find-cache-dir": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.1.tgz", - "integrity": "sha512-t2GDMt3oGC/v+BMwzmllWDuJF/xcDtE5j/fCGbqDD7OLuJkj0cfh1YSA5VKPvwMeLFLNDBkwOKZ2X85jGLVftQ==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.2.tgz", + "integrity": "sha512-wXZV5emFEjrridIgED11OoUKLxiYjAcqot/NJdAkOhlJ+vGzwhOAfcG5OX1jP+S0PcjEn8bdMJv+g2jwQ3Onig==", "dev": true, "dependencies": { "commondir": "^1.0.1", @@ -2630,9 +2630,9 @@ } }, "node_modules/ipfs-unixfs": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/ipfs-unixfs/-/ipfs-unixfs-6.0.4.tgz", - "integrity": "sha512-5ARPcTtDGgFK6jPYWAitgDTxIjEcrqz3+ReIPuFZCcekglt2jS8osoZYSLNtpGDtjGevQtaJAgce+BQDY3ymBA==", + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs/-/ipfs-unixfs-6.0.5.tgz", + "integrity": "sha512-D8Z3EsegLxOBc2L8oMyZw/FRUDQG0ZZAaBRfzMrRsGnj7RFI7OlV1hU54aMeDxFYFviKNnUdsyEFI2zUWmgGvw==", "dependencies": { "err-code": "^3.0.1", "protobufjs": "^6.10.2" @@ -2643,9 +2643,9 @@ } }, "node_modules/ipfs-unixfs-exporter": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/ipfs-unixfs-exporter/-/ipfs-unixfs-exporter-7.0.4.tgz", - "integrity": "sha512-5G6IIAaZlLuK7lFW17u57INnSkqaaZbIqXQWPqKJUncmK3Sq7+m3Yl9IzyP5gsLTM/H/AIPD7xbTqIeuIz+PHQ==", + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs-exporter/-/ipfs-unixfs-exporter-7.0.5.tgz", + "integrity": "sha512-H/fBcBHO4kMivj2JyqwVmp90JIxKEsRpgkyifkZxmslttcTgivrOM3s7xeLuj6EkchkqyHS9+wurdv83WFOFpQ==", "dependencies": { "@ipld/dag-cbor": "^6.0.4", "@ipld/dag-pb": "^2.0.2", @@ -2653,7 +2653,7 @@ "err-code": "^3.0.1", "hamt-sharding": "^2.0.0", "interface-blockstore": "^1.0.0", - "ipfs-unixfs": "^6.0.4", + "ipfs-unixfs": "^6.0.5", "it-last": "^1.0.5", "multiformats": "^9.4.2", "uint8arrays": "^3.0.0" @@ -2664,9 +2664,9 @@ } }, "node_modules/ipfs-unixfs-importer": { - "version": "9.0.4", - "resolved": "https://registry.npmjs.org/ipfs-unixfs-importer/-/ipfs-unixfs-importer-9.0.4.tgz", - "integrity": "sha512-RCl3f6/5zRT6716UYuRZET5iWafi9gvRPmgHhWE0Pmco74T2h/VPNHCgj6Noo85fVCNG5KsGBL38uzONO85MNA==", + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs-importer/-/ipfs-unixfs-importer-9.0.5.tgz", + "integrity": "sha512-+Xxqu7WKC/cFd/IP5bCPw4E29CybU0k/exxNJCCn/QDrSm+o25Dz4IFCLc9jXvffi9Za8gCMywZFeM2HbB5Dyg==", "dependencies": { "@ipld/dag-pb": "^2.0.2", "@multiformats/murmur3": "^1.0.3", @@ -2674,7 +2674,7 @@ "err-code": "^3.0.1", "hamt-sharding": "^2.0.0", "interface-blockstore": "^1.0.0", - "ipfs-unixfs": "^6.0.4", + "ipfs-unixfs": "^6.0.5", "it-all": "^1.0.5", "it-batch": "^1.0.8", "it-first": "^1.0.6", @@ -2690,9 +2690,9 @@ } }, "node_modules/ipfs-utils": { - "version": "8.1.5", - "resolved": "https://registry.npmjs.org/ipfs-utils/-/ipfs-utils-8.1.5.tgz", - "integrity": "sha512-qjERTUy0iXPw5LRPA1OQLzYPjdYb7JQenihYaE0L+yA4NMoC9qhGVrYUqU8yaV0Iu+zk7i6BxoNwg8beWsqjbg==", + "version": "8.1.6", + "resolved": "https://registry.npmjs.org/ipfs-utils/-/ipfs-utils-8.1.6.tgz", + "integrity": "sha512-V/cwb6113DrDhrjDTWImA6+zmJbpdbUkxdxmEQO7it8ykV76bBmzU1ZXSM0QR0qxGy9VW8dkUlPAC2K10VgSmw==", "dependencies": { "abort-controller": "^3.0.0", "any-signal": "^2.1.0", @@ -2707,7 +2707,7 @@ "nanoid": "^3.1.20", "native-abort-controller": "^1.0.3", "native-fetch": "^3.0.0", - "node-fetch": "npm:@achingbrain/node-fetch@^2.6.4", + "node-fetch": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz", "react-native-fetch-api": "^2.0.0", "stream-to-it": "^0.2.2" } @@ -3025,11 +3025,11 @@ } }, "node_modules/is-typed-array": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.7.tgz", - "integrity": "sha512-VxlpTBGknhQ3o7YiVjIhdLU6+oD8dPz/79vvvH4F+S/c8608UCVa9fgDpa1kZgFoUST2DCgacc70UszKgzKuvA==", + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.8.tgz", + "integrity": "sha512-HqH41TNZq2fgtGT8WHVFVJhBVGuY3AnP3Q36K8JKXUxSxRgk/d+7NjmwG2vo2mYmXK8UYZKu0qH8bVP5gEisjA==", "dependencies": { - "available-typed-arrays": "^1.0.4", + "available-typed-arrays": "^1.0.5", "call-bind": "^1.0.2", "es-abstract": "^1.18.5", "foreach": "^2.0.5", @@ -3659,9 +3659,9 @@ } }, "node_modules/mocha": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.0.tgz", - "integrity": "sha512-Kjg/XxYOFFUi0h/FwMOeb6RoroiZ+P1yOfya6NK7h3dNhahrJx1r2XIT3ge4ZQvJM86mdjNA+W5phqRQh7DwCg==", + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.1.tgz", + "integrity": "sha512-0wE74YMgOkCgBUj8VyIDwmLUjTsS13WV1Pg7l0SHea2qzZzlq7MDnfbPsHKcELBRk3+izEVkRofjmClpycudCA==", "dev": true, "dependencies": { "@ungap/promise-all-settled": "1.1.2", @@ -3830,6 +3830,7 @@ "version": "2.6.7", "resolved": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz", "integrity": "sha512-iTASGs+HTFK5E4ZqcMsHmeJ4zodyq8L38lZV33jwqcBJYoUt3HjN4+ot+O9/0b+ke8ddE7UgOtVuZN/OkV19/g==", + "license": "MIT", "engines": { "node": "4.x || >=6.0.0" } @@ -5236,12 +5237,12 @@ } }, "node_modules/sirv": { - "version": "1.0.16", - "resolved": "https://registry.npmjs.org/sirv/-/sirv-1.0.16.tgz", - "integrity": "sha512-x56DISeIgSUGVJrQS3mwu+UvtnzHenKDFBQL+UlAswxwk9b2Cpc0KGVvftoIJZgweOOXbMZzyXFYgVElOuSI1Q==", + "version": "1.0.17", + "resolved": "https://registry.npmjs.org/sirv/-/sirv-1.0.17.tgz", + "integrity": "sha512-qx9go5yraB7ekT7bCMqUHJ5jEaOC/GXBxUWv+jeWnb7WzHUFdcQPGWk7YmAwFBaQBrogpuSqd/azbC2lZRqqmw==", "dev": true, "dependencies": { - "@polka/url": "^1.0.0-next.19", + "@polka/url": "^1.0.0-next.20", "mime": "^2.3.1", "totalist": "^1.0.0" }, @@ -5250,9 +5251,9 @@ } }, "node_modules/sirv/node_modules/@polka/url": { - "version": "1.0.0-next.19", - "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.19.tgz", - "integrity": "sha512-kHR9OHwP9WLpyC0i/WCAQCgf5hXkR9C+/21qxmrn+YwRlDRnBlqrcrFpXxhJTA9LDHJWa/FjoO2LJ12q8iWlEQ==", + "version": "1.0.0-next.20", + "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.20.tgz", + "integrity": "sha512-88p7+M0QGxKpmnkfXjS4V26AnoC/eiqZutE8GLdaI5X12NY75bXSdTY9NkmYb2Xyk1O+MmkuO6Frmsj84V6I8Q==", "dev": true }, "node_modules/slash": { @@ -5962,9 +5963,9 @@ } }, "node_modules/typescript": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", - "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.2.tgz", + "integrity": "sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -6153,16 +6154,16 @@ "dev": true }, "node_modules/which-typed-array": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.6.tgz", - "integrity": "sha512-DdY984dGD5sQ7Tf+x1CkXzdg85b9uEel6nr4UkFg1LoE9OXv3uRuZhe5CoWdawhGACeFpEZXH8fFLQnDhbpm/Q==", + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.7.tgz", + "integrity": "sha512-vjxaB4nfDqwKI0ws7wZpxIlde1XrLX5uB0ZjpfshgmapJMD7jJWhZI+yToJTqaFByF0eNBcYxbjmCzoRP7CfEw==", "dependencies": { - "available-typed-arrays": "^1.0.4", + "available-typed-arrays": "^1.0.5", "call-bind": "^1.0.2", "es-abstract": "^1.18.5", "foreach": "^2.0.5", "has-tostringtag": "^1.0.0", - "is-typed-array": "^1.1.6" + "is-typed-array": "^1.1.7" }, "engines": { "node": ">= 0.4" @@ -6266,9 +6267,9 @@ } }, "node_modules/ws": { - "version": "7.5.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.3.tgz", - "integrity": "sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.4.tgz", + "integrity": "sha512-zP9z6GXm6zC27YtspwH99T3qTG7bBFv2VIkeHstMLrLlDJuzA7tQ5ls3OJ1hOGGCzTQPniNJoHXIAOS0Jljohg==", "dev": true, "engines": { "node": ">=8.3.0" @@ -6794,9 +6795,9 @@ } }, "@ipld/dag-cbor": { - "version": "6.0.9", - "resolved": "https://registry.npmjs.org/@ipld/dag-cbor/-/dag-cbor-6.0.9.tgz", - "integrity": "sha512-Kj8K8z2YMhupPJMHAn3jSVgGl/V7gT3Eki1dCE4bVhbli+vHS6lLObZXAcrTXMMHHYFmkSoOFdvwoYu5AU7lBA==", + "version": "6.0.10", + "resolved": "https://registry.npmjs.org/@ipld/dag-cbor/-/dag-cbor-6.0.10.tgz", + "integrity": "sha512-dGinQkyDKQ5vkgX8JxbXBX2fl2GB+cn6u6a6cm/pTub1WeB/PMoDJ9pU7VSBvHUtGO+ZoueeQ06TgEnO+t9esg==", "requires": { "cborg": "^1.2.1", "multiformats": "^9.0.0" @@ -7085,9 +7086,9 @@ "dev": true }, "@types/node": { - "version": "16.7.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-16.7.2.tgz", - "integrity": "sha512-TbG4TOx9hng8FKxaVrCisdaxKxqEwJ3zwHoCWXZ0Jw6mnvTInpaB99/2Cy4+XxpXtjNv9/TgfGSvZFyfV/t8Fw==" + "version": "16.7.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.7.10.tgz", + "integrity": "sha512-S63Dlv4zIPb8x6MMTgDq5WWRJQe56iBEY0O3SOFA9JrRienkOVDXSXBjjJw6HTNQYSE2JI6GMCR6LVbIMHJVvA==" }, "@types/normalize-package-data": { "version": "2.4.1", @@ -7303,9 +7304,9 @@ "dev": true }, "available-typed-arrays": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.4.tgz", - "integrity": "sha512-SA5mXJWrId1TaQjfxUYghbqQ/hYioKmLJvPJyDuYRtXXenFNMjj4hSSt1Cf1xsuXSXrtxrVC5Ot4eU6cOtBDdA==" + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", + "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==" }, "balanced-match": { "version": "1.0.2", @@ -7836,9 +7837,9 @@ } }, "electron-to-chromium": { - "version": "1.3.818", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.818.tgz", - "integrity": "sha512-c/Z9gIr+jDZAR9q+mn40hEc1NharBT+8ejkarjbCDnBNFviI6hvcC5j2ezkAXru//bTnQp5n6iPi0JA83Tla1Q==", + "version": "1.3.827", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.827.tgz", + "integrity": "sha512-ye+4uQOY/jbjRutMcE/EmOcNwUeo1qo9aKL2tPyb09cU3lmxNeyDF4RWiemmkknW+p29h7dyDqy02higTxc9/A==", "dev": true }, "emoji-regex": { @@ -8040,9 +8041,9 @@ } }, "find-cache-dir": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.1.tgz", - "integrity": "sha512-t2GDMt3oGC/v+BMwzmllWDuJF/xcDtE5j/fCGbqDD7OLuJkj0cfh1YSA5VKPvwMeLFLNDBkwOKZ2X85jGLVftQ==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.2.tgz", + "integrity": "sha512-wXZV5emFEjrridIgED11OoUKLxiYjAcqot/NJdAkOhlJ+vGzwhOAfcG5OX1jP+S0PcjEn8bdMJv+g2jwQ3Onig==", "dev": true, "requires": { "commondir": "^1.0.1", @@ -8457,18 +8458,18 @@ } }, "ipfs-unixfs": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/ipfs-unixfs/-/ipfs-unixfs-6.0.4.tgz", - "integrity": "sha512-5ARPcTtDGgFK6jPYWAitgDTxIjEcrqz3+ReIPuFZCcekglt2jS8osoZYSLNtpGDtjGevQtaJAgce+BQDY3ymBA==", + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs/-/ipfs-unixfs-6.0.5.tgz", + "integrity": "sha512-D8Z3EsegLxOBc2L8oMyZw/FRUDQG0ZZAaBRfzMrRsGnj7RFI7OlV1hU54aMeDxFYFviKNnUdsyEFI2zUWmgGvw==", "requires": { "err-code": "^3.0.1", "protobufjs": "^6.10.2" } }, "ipfs-unixfs-exporter": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/ipfs-unixfs-exporter/-/ipfs-unixfs-exporter-7.0.4.tgz", - "integrity": "sha512-5G6IIAaZlLuK7lFW17u57INnSkqaaZbIqXQWPqKJUncmK3Sq7+m3Yl9IzyP5gsLTM/H/AIPD7xbTqIeuIz+PHQ==", + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs-exporter/-/ipfs-unixfs-exporter-7.0.5.tgz", + "integrity": "sha512-H/fBcBHO4kMivj2JyqwVmp90JIxKEsRpgkyifkZxmslttcTgivrOM3s7xeLuj6EkchkqyHS9+wurdv83WFOFpQ==", "requires": { "@ipld/dag-cbor": "^6.0.4", "@ipld/dag-pb": "^2.0.2", @@ -8476,16 +8477,16 @@ "err-code": "^3.0.1", "hamt-sharding": "^2.0.0", "interface-blockstore": "^1.0.0", - "ipfs-unixfs": "^6.0.4", + "ipfs-unixfs": "^6.0.5", "it-last": "^1.0.5", "multiformats": "^9.4.2", "uint8arrays": "^3.0.0" } }, "ipfs-unixfs-importer": { - "version": "9.0.4", - "resolved": "https://registry.npmjs.org/ipfs-unixfs-importer/-/ipfs-unixfs-importer-9.0.4.tgz", - "integrity": "sha512-RCl3f6/5zRT6716UYuRZET5iWafi9gvRPmgHhWE0Pmco74T2h/VPNHCgj6Noo85fVCNG5KsGBL38uzONO85MNA==", + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/ipfs-unixfs-importer/-/ipfs-unixfs-importer-9.0.5.tgz", + "integrity": "sha512-+Xxqu7WKC/cFd/IP5bCPw4E29CybU0k/exxNJCCn/QDrSm+o25Dz4IFCLc9jXvffi9Za8gCMywZFeM2HbB5Dyg==", "requires": { "@ipld/dag-pb": "^2.0.2", "@multiformats/murmur3": "^1.0.3", @@ -8493,7 +8494,7 @@ "err-code": "^3.0.1", "hamt-sharding": "^2.0.0", "interface-blockstore": "^1.0.0", - "ipfs-unixfs": "^6.0.4", + "ipfs-unixfs": "^6.0.5", "it-all": "^1.0.5", "it-batch": "^1.0.8", "it-first": "^1.0.6", @@ -8505,9 +8506,9 @@ } }, "ipfs-utils": { - "version": "8.1.5", - "resolved": "https://registry.npmjs.org/ipfs-utils/-/ipfs-utils-8.1.5.tgz", - "integrity": "sha512-qjERTUy0iXPw5LRPA1OQLzYPjdYb7JQenihYaE0L+yA4NMoC9qhGVrYUqU8yaV0Iu+zk7i6BxoNwg8beWsqjbg==", + "version": "8.1.6", + "resolved": "https://registry.npmjs.org/ipfs-utils/-/ipfs-utils-8.1.6.tgz", + "integrity": "sha512-V/cwb6113DrDhrjDTWImA6+zmJbpdbUkxdxmEQO7it8ykV76bBmzU1ZXSM0QR0qxGy9VW8dkUlPAC2K10VgSmw==", "requires": { "abort-controller": "^3.0.0", "any-signal": "^2.1.0", @@ -8522,7 +8523,7 @@ "nanoid": "^3.1.20", "native-abort-controller": "^1.0.3", "native-fetch": "^3.0.0", - "node-fetch": "npm:@achingbrain/node-fetch@^2.6.4", + "node-fetch": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz", "react-native-fetch-api": "^2.0.0", "stream-to-it": "^0.2.2" } @@ -8726,11 +8727,11 @@ } }, "is-typed-array": { - "version": "1.1.7", - "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.7.tgz", - "integrity": "sha512-VxlpTBGknhQ3o7YiVjIhdLU6+oD8dPz/79vvvH4F+S/c8608UCVa9fgDpa1kZgFoUST2DCgacc70UszKgzKuvA==", + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.8.tgz", + "integrity": "sha512-HqH41TNZq2fgtGT8WHVFVJhBVGuY3AnP3Q36K8JKXUxSxRgk/d+7NjmwG2vo2mYmXK8UYZKu0qH8bVP5gEisjA==", "requires": { - "available-typed-arrays": "^1.0.4", + "available-typed-arrays": "^1.0.5", "call-bind": "^1.0.2", "es-abstract": "^1.18.5", "foreach": "^2.0.5", @@ -9220,9 +9221,9 @@ } }, "mocha": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.0.tgz", - "integrity": "sha512-Kjg/XxYOFFUi0h/FwMOeb6RoroiZ+P1yOfya6NK7h3dNhahrJx1r2XIT3ge4ZQvJM86mdjNA+W5phqRQh7DwCg==", + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.1.tgz", + "integrity": "sha512-0wE74YMgOkCgBUj8VyIDwmLUjTsS13WV1Pg7l0SHea2qzZzlq7MDnfbPsHKcELBRk3+izEVkRofjmClpycudCA==", "dev": true, "requires": { "@ungap/promise-all-settled": "1.1.2", @@ -9347,8 +9348,7 @@ } }, "node-fetch": { - "version": "npm:@achingbrain/node-fetch@2.6.7", - "resolved": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz", + "version": "https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz", "integrity": "sha512-iTASGs+HTFK5E4ZqcMsHmeJ4zodyq8L38lZV33jwqcBJYoUt3HjN4+ot+O9/0b+ke8ddE7UgOtVuZN/OkV19/g==" }, "node-preload": { @@ -10387,20 +10387,20 @@ } }, "sirv": { - "version": "1.0.16", - "resolved": "https://registry.npmjs.org/sirv/-/sirv-1.0.16.tgz", - "integrity": "sha512-x56DISeIgSUGVJrQS3mwu+UvtnzHenKDFBQL+UlAswxwk9b2Cpc0KGVvftoIJZgweOOXbMZzyXFYgVElOuSI1Q==", + "version": "1.0.17", + "resolved": "https://registry.npmjs.org/sirv/-/sirv-1.0.17.tgz", + "integrity": "sha512-qx9go5yraB7ekT7bCMqUHJ5jEaOC/GXBxUWv+jeWnb7WzHUFdcQPGWk7YmAwFBaQBrogpuSqd/azbC2lZRqqmw==", "dev": true, "requires": { - "@polka/url": "^1.0.0-next.19", + "@polka/url": "^1.0.0-next.20", "mime": "^2.3.1", "totalist": "^1.0.0" }, "dependencies": { "@polka/url": { - "version": "1.0.0-next.19", - "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.19.tgz", - "integrity": "sha512-kHR9OHwP9WLpyC0i/WCAQCgf5hXkR9C+/21qxmrn+YwRlDRnBlqrcrFpXxhJTA9LDHJWa/FjoO2LJ12q8iWlEQ==", + "version": "1.0.0-next.20", + "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.20.tgz", + "integrity": "sha512-88p7+M0QGxKpmnkfXjS4V26AnoC/eiqZutE8GLdaI5X12NY75bXSdTY9NkmYb2Xyk1O+MmkuO6Frmsj84V6I8Q==", "dev": true } } @@ -10938,9 +10938,9 @@ } }, "typescript": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", - "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.2.tgz", + "integrity": "sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==", "dev": true }, "uint8arrays": { @@ -11091,16 +11091,16 @@ "dev": true }, "which-typed-array": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.6.tgz", - "integrity": "sha512-DdY984dGD5sQ7Tf+x1CkXzdg85b9uEel6nr4UkFg1LoE9OXv3uRuZhe5CoWdawhGACeFpEZXH8fFLQnDhbpm/Q==", + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.7.tgz", + "integrity": "sha512-vjxaB4nfDqwKI0ws7wZpxIlde1XrLX5uB0ZjpfshgmapJMD7jJWhZI+yToJTqaFByF0eNBcYxbjmCzoRP7CfEw==", "requires": { - "available-typed-arrays": "^1.0.4", + "available-typed-arrays": "^1.0.5", "call-bind": "^1.0.2", "es-abstract": "^1.18.5", "foreach": "^2.0.5", "has-tostringtag": "^1.0.0", - "is-typed-array": "^1.1.6" + "is-typed-array": "^1.1.7" } }, "wide-align": { @@ -11182,9 +11182,9 @@ } }, "ws": { - "version": "7.5.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.3.tgz", - "integrity": "sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.4.tgz", + "integrity": "sha512-zP9z6GXm6zC27YtspwH99T3qTG7bBFv2VIkeHstMLrLlDJuzA7tQ5ls3OJ1hOGGCzTQPniNJoHXIAOS0Jljohg==", "dev": true, "requires": {} }, diff --git a/src/pack/constants.ts b/src/pack/constants.ts index 78e41d8..c57cab8 100644 --- a/src/pack/constants.ts +++ b/src/pack/constants.ts @@ -7,6 +7,6 @@ export const unixfsImporterOptionsDefault = { maxChunkSize: 262144, hasher: sha256, rawLeaves: true, - wrapWithDirectory: true, + wrapWithDirectory: false, maxChildrenPerNode: 174 } as UserImporterOptions diff --git a/test/pack/index.browser.test.ts b/test/pack/index.browser.test.ts index f9f6153..57ff0a1 100644 --- a/test/pack/index.browser.test.ts +++ b/test/pack/index.browser.test.ts @@ -20,8 +20,26 @@ describe('pack', () => { carParts.push(part) } - expect(root.toString()).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') - expect(carParts.length).to.eql(7) + expect(root.toString()).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') + expect(carParts.length).to.eql(4) + }) + + it('with iterable input and wrapping with directory', async () => { + const { root, out } = await pack({ + input: [{ + path: 'test.txt', + content: new Uint8Array([21, 31]) + }], + blockstore: new Blockstore() + }) + + const carParts = [] + for await (const part of out) { + carParts.push(part) + } + + expect(root.toString()).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') + expect(carParts.length).to.eql(4) }) it('can pack with custom unixfs importer options', async () => { @@ -49,7 +67,7 @@ describe('pack', () => { blockstore: new Blockstore() }) - expect(root.toString()).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(root.toString()).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') }) it('pack does not close provided blockstore', async () => { diff --git a/test/pack/index.node.test.ts b/test/pack/index.node.test.ts index f44b8ee..53d555f 100644 --- a/test/pack/index.node.test.ts +++ b/test/pack/index.node.test.ts @@ -61,7 +61,7 @@ describe('pack', () => { const carReader = await CarReader.fromIterable(inStream) const files = await all(unpack(carReader)) - expect(files).to.have.lengthOf(3) + expect(files).to.have.lengthOf(2) }) it('pack dir to car with filesystem output', async () => { @@ -79,7 +79,7 @@ describe('pack', () => { const carReader = await CarReader.fromIterable(inStream) const files = await all(unpack(carReader)) - expect(files).to.have.lengthOf(3) + expect(files).to.have.lengthOf(2) }) it('pack raw file to car with filesystem output', async () => { @@ -97,7 +97,7 @@ describe('pack', () => { const carReader = await CarReader.fromIterable(inStream) const files = await all(unpack(carReader)) - expect(files).to.have.lengthOf(2) + expect(files).to.have.lengthOf(1) const rawOriginalContent = new Uint8Array(fs.readFileSync(`${__dirname}/../fixtures/file.raw`)) const rawContent = (await all(files[files.length - 1].content()))[0] @@ -121,7 +121,7 @@ describe('pack', () => { const carReader = await CarReader.fromIterable(inStream) const files = await all(unpack(carReader)) - expect(files).to.have.lengthOf(2) + expect(files).to.have.lengthOf(1) const rawOriginalContent = new Uint8Array(fs.readFileSync(`${__dirname}/../fixtures/file.raw`)) const rawContent = (await all(files[files.length - 1].content()))[0] @@ -148,7 +148,7 @@ describe('pack', () => { const carReader = await CarReader.fromIterable(inStream) const files = await all(unpack(carReader)) - expect(files).to.have.lengthOf(2) + expect(files).to.have.lengthOf(1) const rawOriginalContent = new Uint8Array(fs.readFileSync(`${__dirname}/../fixtures/file.raw`)) const rawContent = (await all(files[files.length - 1].content()))[0] @@ -197,7 +197,7 @@ describe('pack', () => { }) expect(car).to.exist - expect(root.toString()).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(root.toString()).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') await blockstore.close() }) @@ -211,7 +211,7 @@ describe('pack', () => { }) expect(car).to.exist - expect(root.toString()).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(root.toString()).to.eql('bafkreiadsbmmn4waznesyuz3bjgrj33xzqhxrk6mz3ksq7meugrachh3qe') await blockstore.close() }) diff --git a/test/unpack/index.browser.test.ts b/test/unpack/index.browser.test.ts index d79ad41..bc425f3 100644 --- a/test/unpack/index.browser.test.ts +++ b/test/unpack/index.browser.test.ts @@ -25,8 +25,8 @@ describe('unpack', () => { const files = await all(unpack(carReader)) expect(files.length).to.eql(1) - expect(files[0].type).to.eql('directory') - expect(files[0].name).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(files[0].type).to.eql('raw') + expect(files[0].name).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') }) }) @@ -40,8 +40,8 @@ describe('unpackStream', () => { }) const files = await all(unpackStream(out, {blockstore: new Blockstore()})) expect(files.length).to.eql(1) - expect(files[0].type).to.eql('directory') - expect(files[0].name).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(files[0].type).to.eql('raw') + expect(files[0].name).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') }) it('with readablestream input', async () => { const { out } = await pack({ @@ -58,8 +58,8 @@ describe('unpackStream', () => { }) const files = await all(unpackStream(stream, {blockstore: new Blockstore()})) expect(files.length).to.eql(1) - expect(files[0].type).to.eql('directory') - expect(files[0].name).to.eql('bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354') + expect(files[0].type).to.eql('raw') + expect(files[0].name).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') }) }) }) From 2d49a1cc5491e7396dd31a183df1a76e0cee5145 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 2 Sep 2021 18:46:59 +0200 Subject: [PATCH 3/3] fix: throw when no path is provided --- src/pack/index.ts | 16 ++++++++-- test/pack/index.browser.test.ts | 54 --------------------------------- test/pack/index.node.test.ts | 24 +++++++++++++-- 3 files changed, 34 insertions(+), 60 deletions(-) diff --git a/src/pack/index.ts b/src/pack/index.ts index 8199c45..abfb448 100644 --- a/src/pack/index.ts +++ b/src/pack/index.ts @@ -28,9 +28,19 @@ export async function pack ({ input, blockstore: userBlockstore, hasher, maxChun throw new Error('missing input file(s)') } - // Disable wrap with directory if we receive byte arrays as input with no path - if (Array.isArray(input) && input.filter((i) => !i.path).length) { - wrapWithDirectory = false + // Transform Web File to Import candidate + if (Array.isArray(input) && input.filter((i) => i.name).length) { + input = input.map((file) => { + if (file.name) { + file.path = file.name + } + return file + }) + } + + // if we receive byte arrays as input with no path it must include a path or wrapWithDirectory should be disabled + if (Array.isArray(input) && input.filter((i) => !i.path).length && wrapWithDirectory !== false) { + throw new Error('inputs with no path provided need to have a path specified or wrapWithDirectory option must be disabled') } const blockstore = userBlockstore ? userBlockstore : new MemoryBlockStore() diff --git a/test/pack/index.browser.test.ts b/test/pack/index.browser.test.ts index 99e1b32..48bc87a 100644 --- a/test/pack/index.browser.test.ts +++ b/test/pack/index.browser.test.ts @@ -51,60 +51,6 @@ describe('pack', () => { expect(carParts.length).to.eql(10) }) - it('can pack with an array input without path (defaults to wrapWithDirectory to false)', async () => { - const { root, out } = await pack({ - input: [{ - content: new Uint8Array([21, 31]) - }], - blockstore: new Blockstore() - }) - - const carParts = [] - for await (const part of out) { - carParts.push(part) - } - - expect(root.toString()).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') - expect(carParts.length).to.eql(4) - }) - - it('can pack with an array input without path in one of the entries (defaults to wrapWithDirectory to false)', async () => { - const { root, out } = await pack({ - input: [{ - path: 'a.txt', - content: new Uint8Array([21, 31]) - }, - { - content: new Uint8Array([22, 32]) - } - ], - blockstore: new Blockstore() - }) - - const carParts = [] - for await (const part of out) { - carParts.push(part) - } - - expect(root.toString()).to.eql('bafkreihdoh3xvolzxa4aa3snjjnhkgigs4rbbsj2qdax5kfbtlfewdmx5q') - expect(carParts.length).to.eql(7) - }) - - it('can pack with an uint8array input without path (defaults to wrapWithDirectory to false)', async () => { - const { root, out } = await pack({ - input: [new Uint8Array([21, 31])], - blockstore: new Blockstore() - }) - - const carParts = [] - for await (const part of out) { - carParts.push(part) - } - - expect(root.toString()).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') - expect(carParts.length).to.eql(4) - }) - it('can pack with custom unixfs importer options', async () => { const { root, out } = await pack({ input: [{ diff --git a/test/pack/index.node.test.ts b/test/pack/index.node.test.ts index d1a14e6..451c3e0 100644 --- a/test/pack/index.node.test.ts +++ b/test/pack/index.node.test.ts @@ -192,12 +192,15 @@ describe('pack', () => { const blockstore = new Blockstore() const { car, root } = await packToBlob({ - input: [new Uint8Array([21, 31])], + input: [{ + path: 'file.txt', + content: new Uint8Array([21, 31]) + }], blockstore }) expect(car).to.exist - expect(root.toString()).to.eql('bafkreifidl2jnal7ycittjrnbki6jasdxwwvpf7fj733vnyhidtusxby4y') + expect(root.toString()).to.eql('bafybeif3hyrtm2skjmldufjid3myfp37sxyqbtz7xe3f2fqyd7ugi33b2a') await blockstore.close() }) @@ -211,7 +214,7 @@ describe('pack', () => { }) expect(car).to.exist - expect(root.toString()).to.eql('bafkreiadsbmmn4waznesyuz3bjgrj33xzqhxrk6mz3ksq7meugrachh3qe') + expect(root.toString()).to.eql('bafybeifspimntdv4o3ykr3qtt3vk5nwhegyzcktqiu2iatwuti66acbpby') await blockstore.close() }) @@ -229,6 +232,21 @@ describe('pack', () => { } throw new Error('pack should throw error with empty input') }) + + it('should error to pack byte array input with wrapWithDirectory enabled and not path', async () => { + const blockstore = new Blockstore() + + try { + await pack({ + input: [new Uint8Array([1, 2, 3])], + blockstore + }) + } catch (err) { + expect(err).to.exist + return + } + throw new Error('pack should throw error when byte array is received as content and no path is provided') + }) }) }) })