Skip to content

Commit 9fcc2e9

Browse files
authored
fix: drop rusha (#184)
* feat: esm * perf: drop rusha * Update README.md * fix: add test messages
1 parent 3e076dd commit 9fcc2e9

9 files changed

Lines changed: 45 additions & 26 deletions

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import junk from 'junk'
88
import joinIterator from 'join-async-iterator'
99
import parallel from 'run-parallel'
1010
import queueMicrotask from 'queue-microtask'
11-
import sha1 from 'simple-sha1'
11+
import { sha1 } from 'uint8-util'
1212
import 'fast-readable-async-iterator'
1313

1414
import getFiles from './get-files.js' // browser exclude

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"piece-length": "^2.0.1",
3030
"queue-microtask": "^1.2.3",
3131
"run-parallel": "^1.2.0",
32-
"simple-sha1": "^3.1.0"
32+
"uint8-util": "^1.0.1"
3333
},
3434
"devDependencies": {
3535
"@webtorrent/semantic-release-config": "1.0.8",

test/browser/basic.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fixtures from 'webtorrent-fixtures'
44
import fs from 'fs'
55
import parseTorrent from 'parse-torrent'
66
import path from 'path'
7-
import sha1 from 'simple-sha1'
7+
import { sha1 } from 'uint8-util'
88
import test from 'tape'
99
import createTorrent from '../../index.js'
1010

@@ -71,7 +71,9 @@ test('create single file torrent', t => {
7171
])
7272

7373
window.parsedTorrent = parsedTorrent
74-
t.equals(sha1.sync(parsedTorrent.infoBuffer), 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36')
74+
sha1(parsedTorrent.infoBuffer, hash => {
75+
t.equals(hash, 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36')
76+
})
7577
})
7678
})
7779

@@ -117,7 +119,8 @@ test('create multi file torrent', t => {
117119
t.deepEquals(parsedTorrent.pieces, [
118120
'1f74648e50a6a6708ec54ab327a163d5536b7ced'
119121
])
120-
121-
t.equals(sha1.sync(parsedTorrent.infoBuffer), '80562f38656b385ea78959010e51a2cc9db41ea0')
122+
sha1(parsedTorrent.infoBuffer, hash => {
123+
t.equals(hash, '80562f38656b385ea78959010e51a2cc9db41ea0')
124+
})
122125
})
123126
})

test/browser/directory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import fs from 'fs'
44
import parseTorrent from 'parse-torrent'
55
import path from 'path'
6-
import sha1 from 'simple-sha1'
6+
import { sha1 } from 'uint8-util'
77
import test from 'tape'
88
import createTorrent from '../../index.js'
99

test/buffer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import createTorrent from '../index.js'
22
import parseTorrent from 'parse-torrent'
33
import path from 'path'
4-
import sha1 from 'simple-sha1'
4+
import { sha1 } from 'uint8-util'
55
import test from 'tape'
66

77
test('create nested torrent with array of buffers', t => {
@@ -42,6 +42,8 @@ test('create nested torrent with array of buffers', t => {
4242
t.deepEquals(parsedTorrent.pieces, [
4343
'5bf1fd927dfb8679496a2e6cf00cbe50c1c87145'
4444
])
45-
t.equals(sha1.sync(parsedTorrent.infoBuffer), '8fa3c08e640db9576156b21f31353402456a0208')
45+
sha1(parsedTorrent.infoBuffer, hash => {
46+
t.equals(hash, '8fa3c08e640db9576156b21f31353402456a0208')
47+
})
4648
})
4749
})

test/fs.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fixtures from 'webtorrent-fixtures'
22
import parseTorrent from 'parse-torrent'
33
import path from 'path'
4-
import sha1 from 'simple-sha1'
4+
import { sha1 } from 'uint8-util'
55
import test from 'tape'
66
import createTorrent from '../index.js'
77

@@ -54,7 +54,9 @@ test('create single file torrent', t => {
5454
'c698de9b0dad92980906c026d8c1408fa08fe4ec'
5555
])
5656

57-
t.equals(sha1.sync(parsedTorrent.infoBuffer), 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36')
57+
sha1(parsedTorrent.infoBuffer, hash => {
58+
t.equals(hash, 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36')
59+
})
5860
})
5961
})
6062

@@ -112,7 +114,9 @@ test('create multi file torrent', t => {
112114
t.deepEquals(parsedTorrent.pieces, [
113115
'1f74648e50a6a6708ec54ab327a163d5536b7ced'
114116
])
115-
t.equals(sha1.sync(parsedTorrent.infoBuffer), '80562f38656b385ea78959010e51a2cc9db41ea0')
117+
sha1(parsedTorrent.infoBuffer, hash => {
118+
t.equals(hash, '80562f38656b385ea78959010e51a2cc9db41ea0')
119+
})
116120
})
117121
})
118122

@@ -165,8 +169,9 @@ test('create multi file torrent with nested directories', t => {
165169
t.deepEquals(parsedTorrent.pieces, [
166170
'47972f2befaee58b6f3860cd39bd56cb33a488f0'
167171
])
168-
169-
t.equals(sha1.sync(parsedTorrent.infoBuffer), '427887e9c03e123f9c8458b1947090edf1c75baa')
172+
sha1(parsedTorrent.infoBuffer, hash => {
173+
t.equals(hash, '427887e9c03e123f9c8458b1947090edf1c75baa')
174+
})
170175
})
171176
})
172177

@@ -225,6 +230,8 @@ test('create multi file torrent with array of paths', t => {
225230
t.deepEquals(parsedTorrent.pieces, [
226231
'1c4e1ba6da4d771ff82025d7cf76e8c368c6c3dd'
227232
])
228-
t.equals(sha1.sync(parsedTorrent.infoBuffer), 'df25a2959378892f6ddaf4a2d7e75174e09878bb')
233+
sha1(parsedTorrent.infoBuffer, hash => {
234+
t.equals(hash, 'df25a2959378892f6ddaf4a2d7e75174e09878bb')
235+
})
229236
})
230237
})

test/mixed.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fixtures from 'webtorrent-fixtures'
22
import fs from 'fs'
33
import parseTorrent from 'parse-torrent'
44
import path from 'path'
5-
import sha1 from 'simple-sha1'
5+
import { sha1 } from 'uint8-util'
66
import test from 'tape'
77
import createTorrent from '../index.js'
88

@@ -65,6 +65,8 @@ test('create multi file torrent with array of mixed types', t => {
6565
t.deepEquals(parsedTorrent.pieces, [
6666
'9ad893bb9aeca601a0fab4ba85bd4a4c18b630e3'
6767
])
68-
t.equals(sha1.sync(parsedTorrent.infoBuffer), 'bad3f8ea0d1d8a55c18a039dd464f1078f83dba2')
68+
sha1(parsedTorrent.infoBuffer, hash => {
69+
t.equals(hash, 'bad3f8ea0d1d8a55c18a039dd464f1078f83dba2')
70+
})
6971
})
7072
})

test/source.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { join } from 'path'
22
import fixtures from 'webtorrent-fixtures'
33
import parseTorrent from 'parse-torrent'
4-
import sha1 from 'simple-sha1'
4+
import { sha1 } from 'uint8-util'
55
import test from 'tape'
66

77
import createTorrent from '../index.js'
@@ -36,8 +36,9 @@ test('verify info-hash without no source set (default)', t => {
3636
t.equal(parsedTorrent.pieceLength, 262144)
3737

3838
t.deepEquals(parsedTorrent.pieces, ['799c11e348d39f1704022b8354502e2f81f3c037'])
39-
40-
t.equals(sha1.sync(parsedTorrent.infoBuffer), 'b4dfce1f956f720c928535ded617d07696a819ef', 'mktorrent hash with no source')
39+
sha1(parsedTorrent.infoBuffer, hash => {
40+
t.equals(hash, 'b4dfce1f956f720c928535ded617d07696a819ef', 'mktorrent hash with no source')
41+
})
4142
})
4243
})
4344

@@ -72,7 +73,8 @@ test('verify info-hash an additional source attribute set on the info dict (a wa
7273
t.equal(parsedTorrent.pieceLength, 262144)
7374

7475
t.deepEquals(parsedTorrent.pieces, ['799c11e348d39f1704022b8354502e2f81f3c037'])
75-
76-
t.equals(sha1.sync(parsedTorrent.infoBuffer), 'a9499b56289356a3d5b8636387deb83709b8fa42', 'mktorrent run with -s SOURCE')
76+
sha1(parsedTorrent.infoBuffer, hash => {
77+
t.equals(hash, 'a9499b56289356a3d5b8636387deb83709b8fa42', 'mktorrent run with -s SOURCE')
78+
})
7779
})
7880
})

test/stream.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fixtures from 'webtorrent-fixtures'
22
import fs from 'fs'
33
import parseTorrent from 'parse-torrent'
44
import path from 'path'
5-
import sha1 from 'simple-sha1'
5+
import { sha1 } from 'uint8-util'
66
import test from 'tape'
77
import createTorrent from '../index.js'
88

@@ -57,8 +57,9 @@ test('create single file torrent from a stream', t => {
5757
'56dcc242d03293e9446cf5e457d8eb3d9588fd90',
5858
'c698de9b0dad92980906c026d8c1408fa08fe4ec'
5959
])
60-
61-
t.equals(sha1.sync(parsedTorrent.infoBuffer), 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36')
60+
sha1(parsedTorrent.infoBuffer, hash => {
61+
t.equals(hash, 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36')
62+
})
6263
})
6364
})
6465

@@ -111,7 +112,9 @@ test('create multi file torrent with streams', t => {
111112
t.deepEquals(parsedTorrent.pieces, [
112113
'1f74648e50a6a6708ec54ab327a163d5536b7ced'
113114
])
114-
t.equals(sha1.sync(parsedTorrent.infoBuffer), '80562f38656b385ea78959010e51a2cc9db41ea0')
115+
sha1(parsedTorrent.infoBuffer, hash => {
116+
t.equals(hash, '80562f38656b385ea78959010e51a2cc9db41ea0')
117+
})
115118
})
116119
})
117120

0 commit comments

Comments
 (0)