Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

wip: example with deno #11

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/ipfs-101-deno/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, how are you today? Welcome to the Distributed Web!
33 changes: 33 additions & 0 deletions examples/ipfs-101-deno/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createRequire } from "https://deno.land/std@0.102.0/node/module.ts";

// import.meta.url will be the location of "this" module (like `__filename` in
// Node.js), and then serve as the root for your "package", where the
// `package.json` is expected to be, and where the `node_modules` will be used
// for resolution of packages.
const require = createRequire(import.meta.url);

const all = require('it-all')
const uint8ArrayConcat = require('uint8arrays/concat')
const uint8ArrayFromString = require('uint8arrays/from-string')
const uint8ArrayToString = require('uint8arrays/to-string')
const IPFS = require("ipfs");

async function main () {
const node = await IPFS.create()
const version = await node.version()

console.log('Version:', version.version)

const file = await node.add({
path: 'hello.txt',
content: uint8ArrayFromString('Hello World 101')
})

console.log('Added file:', file.path, file.cid.toString())

const data = uint8ArrayConcat(await all(node.cat(file.cid)))

console.log('Added file contents:', uint8ArrayToString(data))
}

main()
27 changes: 27 additions & 0 deletions examples/ipfs-101-deno/jspm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

import all from 'https://dev.jspm.io/it-all'
import uint8ArrayConcat from 'https://dev.jspm.io/uint8arrays/concat'
import uint8ArrayFromString from 'https://dev.jspm.io/uint8arrays/from-string'
import uint8ArrayToString from 'https://dev.jspm.io/uint8arrays/to-string'
import IPFS from 'https://dev.jspm.io/ipfs'

async function main () {
const node = await IPFS.create()
const version = await node.version()

console.log('Version:', version.version)

const file = await node.add({
path: 'hello.txt',
content: uint8ArrayFromString('Hello World 101')
})

console.log('Added file:', file.path, file.cid.toString())

const data = uint8ArrayConcat(await all(node.cat(file.cid)))

console.log('Added file contents:', uint8ArrayToString(data))
}

main()
21 changes: 21 additions & 0 deletions examples/ipfs-101-deno/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "example-ipfs-101-deno",
"version": "1.0.0",
"private": true,
"description": "Using ipfs with deno",
"license": "MIT",
"scripts": {
"clean": "echo 'Nothing to clean...'",
"start": "deno run --allow-read=node_modules --unstable --allow-env index.ts",
"serve": "npm run start",
"test:example": "node tests/test.js"
},
"devDependencies": {
"test-util-ipfs-example": "^1.0.2"
},
"dependencies": {
"ipfs": "^0.56.0",
"it-all": "^1.0.4",
"uint8arrays": "^2.1.6"
}
}
11 changes: 11 additions & 0 deletions examples/ipfs-101-deno/tests/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'

const { node } = require('test-util-ipfs-example');
const path = require('path')

async function test () {
await node.waitForOutput('Added file contents: Hello World 101', 'node', [path.resolve(__dirname, '../index.js')])
await node.waitForOutput('Added file contents: Hello World 101', 'node', [path.resolve(__dirname, '../jspm.js')])
}

test();
2 changes: 1 addition & 1 deletion examples/ipfs-101/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "this package.json needs to exist because of new npm config https://github.com/ipfs/js-ipfs/issues/977#issuecomment-326741092",
"license": "MIT",
"author": "David Dias <daviddias@ipfs.io>",
"main": "1.js",
"main": "index.js",
"scripts": {
"clean": "echo 'Nothing to clean...'",
"start": "node index.js",
Expand Down