Skip to content

Commit dcd6f77

Browse files
authored
feat: import code from monorepo (#25)
adds new http lib adds iso textencoder shim plus tests
1 parent 201b718 commit dcd6f77

File tree

11 files changed

+517
-22
lines changed

11 files changed

+517
-22
lines changed

.aegir.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'use strict'
2+
3+
const { promisify } = require('util')
4+
const http = require('http')
5+
const url = require('url')
6+
const querystring = require('querystring')
7+
8+
const echoServer = async (port = 3000) => {
9+
const server = http.createServer()
10+
11+
server.on('request', (request, response) => {
12+
try {
13+
14+
const uri = url.parse(request.url)
15+
const qs = uri.query ? querystring.parse(uri.query) : {}
16+
const status = qs.status || 200
17+
const contentType = qs.contentType || 'text/plain'
18+
19+
const headers = {
20+
'Access-Control-Allow-Origin': '*'
21+
}
22+
23+
if (qs.body) {
24+
headers['Content-Type'] = contentType
25+
headers['Content-Length'] = qs.body.length
26+
}
27+
28+
response.writeHead(status, headers)
29+
30+
if (qs.body) {
31+
response.end(qs.body)
32+
} else {
33+
request.pipe(response)
34+
}
35+
36+
} catch (err) {
37+
console.error(err)
38+
}
39+
})
40+
41+
await promisify(server.listen.bind(server))(port)
42+
43+
return {
44+
stop: promisify(server.close.bind(server))
45+
}
46+
}
47+
48+
let echo
49+
50+
module.exports = {
51+
hooks: {
52+
pre: async () => {
53+
echo = await echoServer()
54+
},
55+
post: async () => {
56+
await echo.stop()
57+
}
58+
}
59+
}

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
# 🔒 Archived <!-- omit in toc -->
2-
3-
The contents of this repo have been merged into [ipfs/js-ipfs](https://github.com/ipfs/js-ipfs).
4-
5-
Please open [issues](https://github.com/ipfs/js-ipfs/issues) or submit [PRs](https://github.com/ipfs/js-ipfs/pulls) there.
6-
7-
# js-ipfs-utils
1+
# js-ipfs-utils <!-- omit in toc -->
82

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

3024
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.
3125

32-
## Lead Maintainer
26+
## Lead Maintainer <!-- omit in toc -->
3327

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

30+
## Table of Contents <!-- omit in toc -->
31+
32+
- [Install](#install)
33+
- [Usage](#usage)
34+
- [Functions](#functions)
35+
- [General Use](#general-use)
36+
- [TODO](#todo)
37+
- [Data Struct Wrangling](#data-struct-wrangling)
38+
- [TODO](#todo-1)
39+
- [Core API](#core-api)
40+
- [TODO](#todo-2)
41+
- [Contribute](#contribute)
42+
- [License](#license)
43+
3644
## Install
3745

3846

@@ -64,7 +72,7 @@ validateAddInput(Buffer.from('test'))
6472

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

67-
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).
75+
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).
6876

6977
## License
7078

package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,26 @@
2626
},
2727
"license": "MIT",
2828
"dependencies": {
29-
"buffer": "^5.2.1",
29+
"abort-controller": "^3.0.0",
30+
"buffer": "^5.4.2",
3031
"err-code": "^2.0.0",
3132
"fs-extra": "^8.1.0",
3233
"is-electron": "^2.2.0",
34+
"iso-url": "^0.4.7",
3335
"it-glob": "0.0.7",
34-
"ky": "^0.15.0",
35-
"ky-universal": "^0.3.0",
36+
"merge-options": "^2.0.0",
37+
"node-fetch": "^2.6.0",
3638
"stream-to-it": "^0.2.0"
3739
},
3840
"devDependencies": {
39-
"aegir": "^20.4.1",
41+
"aegir": "21.3.0",
4042
"chai": "^4.2.0",
4143
"chai-as-promised": "^7.1.1",
44+
"delay": "^4.3.0",
4245
"dirty-chai": "^2.0.1",
43-
"it-all": "^1.0.1"
46+
"it-all": "^1.0.1",
47+
"it-drain": "^1.0.0",
48+
"it-to-stream": "^0.1.1"
4449
},
4550
"contributors": [
4651
"Alan Shaw <alan.shaw@protocol.ai>",
@@ -49,6 +54,7 @@
4954
"Marcin Rataj <lidel@lidel.org>"
5055
],
5156
"browser": {
52-
"fs-extra": false
57+
"fs-extra": false,
58+
"./src/text-encoder.js": "./src/text-encoder.browser.js"
5359
}
5460
}

src/files/normalise-input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function toAsyncIterable (input) {
223223
})()
224224
}
225225

226-
throw errCode(new Error(`Unexpected input: ${input}`, 'ERR_UNEXPECTED_INPUT'))
226+
throw errCode(new Error(`Unexpected input: ${input}`), 'ERR_UNEXPECTED_INPUT')
227227
}
228228

229229
function toBuffer (chunk) {

src/files/url-source.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
'use strict'
22

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

65
module.exports = async function * urlSource (url, options) {
76
options = options || {}
8-
9-
const { body } = await ky.get(url)
7+
const http = new Http()
108

119
yield {
1210
path: decodeURIComponent(new URL(url).pathname.split('/').pop() || ''),
13-
content: toIterable(body)
11+
content: await http.iterator(url, { method: 'get' })
1412
}
1513
}

0 commit comments

Comments
 (0)