Skip to content

Commit

Permalink
feat: import code from monorepo (#25)
Browse files Browse the repository at this point in the history
adds new http lib
adds iso textencoder shim
plus tests
  • Loading branch information
achingbrain authored Mar 20, 2020
1 parent 201b718 commit dcd6f77
Show file tree
Hide file tree
Showing 11 changed files with 517 additions and 22 deletions.
59 changes: 59 additions & 0 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict'

const { promisify } = require('util')
const http = require('http')
const url = require('url')
const querystring = require('querystring')

const echoServer = async (port = 3000) => {
const server = http.createServer()

server.on('request', (request, response) => {
try {

const uri = url.parse(request.url)
const qs = uri.query ? querystring.parse(uri.query) : {}
const status = qs.status || 200
const contentType = qs.contentType || 'text/plain'

const headers = {
'Access-Control-Allow-Origin': '*'
}

if (qs.body) {
headers['Content-Type'] = contentType
headers['Content-Length'] = qs.body.length
}

response.writeHead(status, headers)

if (qs.body) {
response.end(qs.body)
} else {
request.pipe(response)
}

} catch (err) {
console.error(err)
}
})

await promisify(server.listen.bind(server))(port)

return {
stop: promisify(server.close.bind(server))
}
}

let echo

module.exports = {
hooks: {
pre: async () => {
echo = await echoServer()
},
post: async () => {
await echo.stop()
}
}
}
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
# 🔒 Archived <!-- omit in toc -->

The contents of this repo have been merged into [ipfs/js-ipfs](https://github.com/ipfs/js-ipfs).

Please open [issues](https://github.com/ipfs/js-ipfs/issues) or submit [PRs](https://github.com/ipfs/js-ipfs/pulls) there.

# js-ipfs-utils
# js-ipfs-utils <!-- omit in toc -->

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
Expand All @@ -29,10 +23,24 @@ The IPFS ecosystem has lots of repos with it comes several problems like:

These problems are the motivation for this package, having shared logic in this package avoids creating cyclic dependencies, centralizes common use modules/functions (exactly like aegir does for the tooling), semantic versioning for 3rd party dependencies is handled in one single place (a good example is going from streams 2 to 3) and maintainers should only care about having `ipfs-utils` updated.

## Lead Maintainer
## Lead Maintainer <!-- omit in toc -->

[Hugo Dias](https://github.com/hugomrdias)

## Table of Contents <!-- omit in toc -->

- [Install](#install)
- [Usage](#usage)
- [Functions](#functions)
- [General Use](#general-use)
- [TODO](#todo)
- [Data Struct Wrangling](#data-struct-wrangling)
- [TODO](#todo-1)
- [Core API](#core-api)
- [TODO](#todo-2)
- [Contribute](#contribute)
- [License](#license)

## Install


Expand Down Expand Up @@ -64,7 +72,7 @@ validateAddInput(Buffer.from('test'))

Contributions welcome. Please check out [the issues](https://github.com/ipfs/js-ipfs-utils/issues).

Check out our [contributing document](https://github.com/ipfs/community/blob/master/contributing.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
Check out our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).

## License

Expand Down
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,26 @@
},
"license": "MIT",
"dependencies": {
"buffer": "^5.2.1",
"abort-controller": "^3.0.0",
"buffer": "^5.4.2",
"err-code": "^2.0.0",
"fs-extra": "^8.1.0",
"is-electron": "^2.2.0",
"iso-url": "^0.4.7",
"it-glob": "0.0.7",
"ky": "^0.15.0",
"ky-universal": "^0.3.0",
"merge-options": "^2.0.0",
"node-fetch": "^2.6.0",
"stream-to-it": "^0.2.0"
},
"devDependencies": {
"aegir": "^20.4.1",
"aegir": "21.3.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"delay": "^4.3.0",
"dirty-chai": "^2.0.1",
"it-all": "^1.0.1"
"it-all": "^1.0.1",
"it-drain": "^1.0.0",
"it-to-stream": "^0.1.1"
},
"contributors": [
"Alan Shaw <alan.shaw@protocol.ai>",
Expand All @@ -49,6 +54,7 @@
"Marcin Rataj <lidel@lidel.org>"
],
"browser": {
"fs-extra": false
"fs-extra": false,
"./src/text-encoder.js": "./src/text-encoder.browser.js"
}
}
2 changes: 1 addition & 1 deletion src/files/normalise-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function toAsyncIterable (input) {
})()
}

throw errCode(new Error(`Unexpected input: ${input}`, 'ERR_UNEXPECTED_INPUT'))
throw errCode(new Error(`Unexpected input: ${input}`), 'ERR_UNEXPECTED_INPUT')
}

function toBuffer (chunk) {
Expand Down
8 changes: 3 additions & 5 deletions src/files/url-source.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
'use strict'

const { default: ky } = require('ky-universal')
const toIterable = require('stream-to-it/source')
const Http = require('../http')

module.exports = async function * urlSource (url, options) {
options = options || {}

const { body } = await ky.get(url)
const http = new Http()

yield {
path: decodeURIComponent(new URL(url).pathname.split('/').pop() || ''),
content: toIterable(body)
content: await http.iterator(url, { method: 'get' })
}
}
Loading

0 comments on commit dcd6f77

Please sign in to comment.