Skip to content

Commit

Permalink
feat: esm (#80)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: ESM only
  • Loading branch information
ThaUnknown committed Dec 6, 2022
1 parent 2f7150c commit 022307e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ This package should be used with [bittorrent-protocol](https://www.npmjs.com/pac
Say you're already using `bittorrent-protocol`. Your code might look something like this:

```js
const Protocol = require('bittorrent-protocol')
const net = require('net')
import Protocol from 'bittorrent-protocol'
import net from 'net'

net.createServer(socket => {
var wire = new Protocol()
Expand All @@ -48,9 +48,9 @@ net.createServer(socket => {
To add support for BEP 9, simply modify your code like this:

```js
const Protocol = require('bittorrent-protocol')
const net = require('net')
const ut_metadata = require('ut_metadata')
import Protocol from 'bittorrent-protocol'
import net from 'net'
import ut_metadata from 'ut_metadata'

net.createServer(socket => {
const wire = new Protocol()
Expand Down
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/*! ut_metadata. MIT License. WebTorrent LLC <https://webtorrent.io/opensource> */
const { EventEmitter } = require('events')
const bencode = require('bencode')
const BitField = require('bitfield').default
const debug = require('debug')('ut_metadata')
const sha1 = require('simple-sha1')
import { EventEmitter } from 'events'
import bencode from 'bencode'
import BitField from 'bitfield'
import Debug from 'debug'
import sha1 from 'simple-sha1'

const debug = Debug('ut_metadata')

const MAX_METADATA_SIZE = 1E7 // 10 MB
const BITFIELD_GROW = 1E3
const PIECE_LENGTH = 1 << 14 // 16 KiB

module.exports = metadata => {
export default metadata => {
class utMetadata extends EventEmitter {
constructor (wire) {
super()
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"bugs": {
"url": "https://github.com/webtorrent/ut_metadata/issues"
},
"type": "module",
"dependencies": {
"bencode": "^2.0.1",
"bitfield": "^4.0.0",
Expand Down Expand Up @@ -37,7 +38,12 @@
"ut_metadata"
],
"license": "MIT",
"main": "index.js",
"engines": {
"node": ">=12.20.0"
},
"exports": {
"import": "./index.js"
},
"repository": {
"type": "git",
"url": "git://github.com/webtorrent/ut_metadata.git"
Expand Down
12 changes: 7 additions & 5 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const { leavesMetadata } = require('webtorrent-fixtures')
const bencode = require('bencode')
const Protocol = require('bittorrent-protocol')
const test = require('tape')
const utMetadata = require('../')
import fixtures from 'webtorrent-fixtures'
import bencode from 'bencode'
import Protocol from 'bittorrent-protocol'
import test from 'tape'
import utMetadata from '../index.js'

const { leavesMetadata } = fixtures

test('wire.use(utMetadata())', t => {
const wire = new Protocol()
Expand Down
12 changes: 7 additions & 5 deletions test/fetch.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const { leavesMetadata, sintel } = require('webtorrent-fixtures')
const bencode = require('bencode')
const Protocol = require('bittorrent-protocol')
const test = require('tape')
const utMetadata = require('../')
import fixtures from 'webtorrent-fixtures'
import bencode from 'bencode'
import Protocol from 'bittorrent-protocol'
import test from 'tape'
import utMetadata from '../index.js'

const { leavesMetadata, sintel } = fixtures

const id1 = Buffer.from('01234567890123456789')
const id2 = Buffer.from('12345678901234567890')
Expand Down
1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "test",
"version": "0.0.0",
"type": "module",
"browserify": {
"transform": ["brfs"]
}
Expand Down

0 comments on commit 022307e

Please sign in to comment.