diff --git a/examples/download/.gitignore b/examples/download-browser/.gitignore similarity index 100% rename from examples/download/.gitignore rename to examples/download-browser/.gitignore diff --git a/examples/download/README.md b/examples/download-browser/README.md similarity index 100% rename from examples/download/README.md rename to examples/download-browser/README.md diff --git a/examples/download/esbuild.js b/examples/download-browser/esbuild.js similarity index 100% rename from examples/download/esbuild.js rename to examples/download-browser/esbuild.js diff --git a/examples/download/index.html b/examples/download-browser/index.html similarity index 100% rename from examples/download/index.html rename to examples/download-browser/index.html diff --git a/examples/download/index.js b/examples/download-browser/index.js similarity index 100% rename from examples/download/index.js rename to examples/download-browser/index.js diff --git a/examples/download/package.json b/examples/download-browser/package.json similarity index 82% rename from examples/download/package.json rename to examples/download-browser/package.json index 1d32f3b..39ec1cb 100644 --- a/examples/download/package.json +++ b/examples/download-browser/package.json @@ -1,5 +1,5 @@ { - "name": "@codex-storage/sdk-js-download-example", + "name": "@codex-storage/sdk-js-download-browser-example", "version": "1.0.0", "main": "index.js", "scripts": { @@ -15,4 +15,4 @@ "esbuild": "^0.25.1", "prettier": "^3.5.3" } -} +} \ No newline at end of file diff --git a/examples/download-node/.gitignore b/examples/download-node/.gitignore new file mode 100644 index 0000000..91097d8 --- /dev/null +++ b/examples/download-node/.gitignore @@ -0,0 +1 @@ +index.bundle.js \ No newline at end of file diff --git a/examples/download-node/README.md b/examples/download-node/README.md new file mode 100644 index 0000000..a23bd6b --- /dev/null +++ b/examples/download-node/README.md @@ -0,0 +1,19 @@ +# Download example + +Small example to show how to download a file in node with Codex. + +## Install dependencies + +```bash +npm install +``` + +## Run node + +```bash +CODEX_CID=REPLACE_BY_YOUR_CID node index.js +``` + +The response will be displayed as text, so it is better to test with .txt files. + +Note: You can define `CODEX_NODE_URL`, default value is "http://localhost:8080". diff --git a/examples/download-node/index.js b/examples/download-node/index.js new file mode 100644 index 0000000..efc6345 --- /dev/null +++ b/examples/download-node/index.js @@ -0,0 +1,17 @@ +import { Codex } from "@codex-storage/sdk-js"; + +async function main() { + const codex = new Codex( + process.env.CODEX_NODE_URL || "http://localhost:8080" + ); + + const data = codex.data; + + const cid = process.env.CODEX_CID; + + const result = await data.networkDownloadStream(cid); + + console.info(await result.data.text()); +} + +main(); diff --git a/examples/download-node/package-lock.json b/examples/download-node/package-lock.json new file mode 100644 index 0000000..71191a0 --- /dev/null +++ b/examples/download-node/package-lock.json @@ -0,0 +1,74 @@ +{ + "name": "@codex-storage/sdk-js-download-node-example", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@codex-storage/sdk-js-download-node-example", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@codex-storage/sdk-js": "../..", + "undici": "^7.7.0" + }, + "devDependencies": { + "prettier": "^3.5.3" + } + }, + "..": { + "extraneous": true + }, + "../..": { + "name": "@codex-storage/sdk-js", + "version": "0.1.2", + "license": "MIT", + "dependencies": { + "valibot": "^1.0.0" + }, + "devDependencies": { + "@tsconfig/strictest": "^2.0.5", + "@types/node": "^22.13.17", + "oas-normalize": "^13.1.2", + "openapi-typescript": "^7.6.1", + "prettier": "^3.5.3", + "tsup": "^8.3.6", + "typescript": "^5.8.2", + "vitest": "^3.1.1" + }, + "engines": { + "node": ">=20.18.1" + }, + "peerDependencies": { + "undici": "^7.7.0" + } + }, + "node_modules/@codex-storage/sdk-js": { + "resolved": "../..", + "link": true + }, + "node_modules/prettier": { + "version": "3.5.3", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/undici": { + "version": "7.10.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-7.10.0.tgz", + "integrity": "sha512-u5otvFBOBZvmdjWLVW+5DAc9Nkq8f24g0O9oY7qw2JVIF1VocIFoyz9JFkuVOS2j41AufeO0xnlweJ2RLT8nGw==", + "license": "MIT", + "engines": { + "node": ">=20.18.1" + } + } + } +} diff --git a/examples/download-node/package.json b/examples/download-node/package.json new file mode 100644 index 0000000..dc6cbd1 --- /dev/null +++ b/examples/download-node/package.json @@ -0,0 +1,18 @@ +{ + "name": "@codex-storage/sdk-js-download-node-example", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "build": "node esbuild.js" + }, + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "@codex-storage/sdk-js": "../..", + "undici": "^7.7.0" + }, + "devDependencies": { + "prettier": "^3.5.3" + } +} \ No newline at end of file