hypercore 9.11.0 → 10.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/.github/workflows/test-node.yml +3 -4
  2. package/README.md +123 -409
  3. package/__snapshots__/test/storage.js.snapshot.cjs +15 -0
  4. package/examples/announce.js +19 -0
  5. package/examples/basic.js +10 -0
  6. package/examples/http.js +123 -0
  7. package/examples/lookup.js +20 -0
  8. package/index.js +362 -1597
  9. package/lib/bitfield.js +113 -285
  10. package/lib/block-encryption.js +68 -0
  11. package/lib/block-store.js +58 -0
  12. package/lib/core.js +468 -0
  13. package/lib/extensions.js +76 -0
  14. package/lib/merkle-tree.js +1110 -0
  15. package/lib/messages.js +571 -0
  16. package/lib/mutex.js +39 -0
  17. package/lib/oplog.js +224 -0
  18. package/lib/protocol.js +525 -0
  19. package/lib/random-iterator.js +46 -0
  20. package/lib/remote-bitfield.js +24 -0
  21. package/lib/replicator.js +857 -0
  22. package/package.json +44 -45
  23. package/test/basic.js +59 -471
  24. package/test/bitfield.js +48 -133
  25. package/test/core.js +290 -0
  26. package/test/encodings.js +18 -0
  27. package/test/encryption.js +123 -0
  28. package/test/extension.js +71 -0
  29. package/test/helpers/index.js +23 -0
  30. package/test/merkle-tree.js +518 -0
  31. package/test/mutex.js +137 -0
  32. package/test/oplog.js +399 -0
  33. package/test/preload.js +72 -0
  34. package/test/replicate.js +227 -824
  35. package/test/sessions.js +173 -0
  36. package/test/storage.js +31 -0
  37. package/test/user-data.js +47 -0
  38. package/bench/all.sh +0 -65
  39. package/bench/copy-64kb-blocks.js +0 -51
  40. package/bench/helpers/read-throttled.js +0 -27
  41. package/bench/helpers/read.js +0 -47
  42. package/bench/helpers/write.js +0 -29
  43. package/bench/read-16kb-blocks-proof-throttled.js +0 -1
  44. package/bench/read-16kb-blocks-proof.js +0 -1
  45. package/bench/read-16kb-blocks-throttled.js +0 -1
  46. package/bench/read-16kb-blocks.js +0 -1
  47. package/bench/read-512b-blocks.js +0 -1
  48. package/bench/read-64kb-blocks-linear-batch.js +0 -18
  49. package/bench/read-64kb-blocks-linear.js +0 -18
  50. package/bench/read-64kb-blocks-proof.js +0 -1
  51. package/bench/read-64kb-blocks.js +0 -1
  52. package/bench/replicate-16kb-blocks.js +0 -19
  53. package/bench/replicate-64kb-blocks.js +0 -19
  54. package/bench/write-16kb-blocks.js +0 -1
  55. package/bench/write-512b-blocks.js +0 -1
  56. package/bench/write-64kb-blocks-static.js +0 -1
  57. package/bench/write-64kb-blocks.js +0 -1
  58. package/example.js +0 -23
  59. package/lib/cache.js +0 -26
  60. package/lib/crypto.js +0 -5
  61. package/lib/replicate.js +0 -829
  62. package/lib/safe-buffer-equals.js +0 -6
  63. package/lib/storage.js +0 -421
  64. package/lib/tree-index.js +0 -183
  65. package/test/ack.js +0 -306
  66. package/test/audit.js +0 -36
  67. package/test/cache.js +0 -93
  68. package/test/compat.js +0 -209
  69. package/test/copy.js +0 -377
  70. package/test/default-storage.js +0 -51
  71. package/test/extensions.js +0 -137
  72. package/test/get.js +0 -64
  73. package/test/head.js +0 -65
  74. package/test/helpers/create-tracking-ram.js +0 -27
  75. package/test/helpers/create.js +0 -6
  76. package/test/helpers/replicate.js +0 -4
  77. package/test/seek.js +0 -234
  78. package/test/selections.js +0 -95
  79. package/test/set-uploading-downloading.js +0 -91
  80. package/test/stats.js +0 -77
  81. package/test/streams.js +0 -162
  82. package/test/timeouts.js +0 -22
  83. package/test/tree-index.js +0 -841
  84. package/test/update.js +0 -156
  85. package/test/value-encoding.js +0 -52
package/test/streams.js DELETED
@@ -1,162 +0,0 @@
1
- var tape = require('tape')
2
- var collect = require('stream-collector')
3
- var create = require('./helpers/create')
4
- var bufferFrom = require('buffer-from')
5
-
6
- function test (batch = 1) {
7
- tape('createReadStream to createWriteStream', function (t) {
8
- var feed1 = create()
9
- var feed2 = create()
10
-
11
- feed1.append(['hello', 'world'], function () {
12
- var r = feed1.createReadStream({ batch })
13
- var w = feed2.createWriteStream()
14
-
15
- r.pipe(w).on('finish', function () {
16
- collect(feed2.createReadStream({ batch }), function (err, data) {
17
- t.error(err, 'no error')
18
- t.same(data, [bufferFrom('hello'), bufferFrom('world')])
19
- t.end()
20
- })
21
- })
22
- })
23
- })
24
-
25
- tape('createReadStream with start, end', function (t) {
26
- var feed = create({ valueEncoding: 'utf-8' })
27
-
28
- feed.append(['hello', 'multiple', 'worlds'], function () {
29
- collect(feed.createReadStream({ start: 1, end: 2, batch }), function (err, data) {
30
- t.error(err, 'no error')
31
- t.same(data, ['multiple'])
32
- t.end()
33
- })
34
- })
35
- })
36
-
37
- tape('createReadStream with start, no end', function (t) {
38
- var feed = create({ valueEncoding: 'utf-8' })
39
-
40
- feed.append(['hello', 'multiple', 'worlds'], function () {
41
- collect(feed.createReadStream({ start: 1, batch }), function (err, data) {
42
- t.error(err, 'no error')
43
- t.same(data, ['multiple', 'worlds'])
44
- t.end()
45
- })
46
- })
47
- })
48
-
49
- tape('createReadStream with no start, end', function (t) {
50
- var feed = create({ valueEncoding: 'utf-8' })
51
-
52
- feed.append(['hello', 'multiple', 'worlds'], function () {
53
- collect(feed.createReadStream({ end: 2, batch }), function (err, data) {
54
- t.error(err, 'no error')
55
- t.same(data, ['hello', 'multiple'])
56
- t.end()
57
- })
58
- })
59
- })
60
-
61
- tape('createReadStream with live: true', function (t) {
62
- var feed = create({ valueEncoding: 'utf-8' })
63
- var expected = ['a', 'b', 'c', 'd', 'e']
64
-
65
- t.plan(expected.length)
66
-
67
- var rs = feed.createReadStream({ live: true, batch })
68
-
69
- rs.on('data', function (data) {
70
- t.same(data, expected.shift())
71
- })
72
-
73
- rs.on('end', function () {
74
- t.fail('should never end')
75
- })
76
-
77
- feed.append('a', function () {
78
- feed.append('b', function () {
79
- feed.append(['c', 'd', 'e'])
80
- })
81
- })
82
- })
83
-
84
- tape('createReadStream with live: true after append', function (t) {
85
- var feed = create({ valueEncoding: 'utf-8' })
86
- var expected = ['a', 'b', 'c', 'd', 'e']
87
-
88
- t.plan(expected.length)
89
-
90
- feed.append(['a', 'b'], function () {
91
- var rs = feed.createReadStream({ live: true, batch })
92
-
93
- rs.on('data', function (data) {
94
- t.same(data, expected.shift())
95
- })
96
-
97
- rs.on('end', function () {
98
- t.fail('should never end')
99
- })
100
-
101
- feed.append(['c', 'd', 'e'])
102
- })
103
- })
104
-
105
- tape('createReadStream with live: true and tail: true', function (t) {
106
- var feed = create({ valueEncoding: 'utf-8' })
107
- var expected = ['c', 'd', 'e']
108
-
109
- t.plan(expected.length)
110
-
111
- feed.append(['a', 'b'], function () {
112
- var rs = feed.createReadStream({ live: true, tail: true, batch })
113
-
114
- rs.on('data', function (data) {
115
- t.same(data, expected.shift())
116
- })
117
-
118
- rs.on('end', function () {
119
- t.fail('should never end')
120
- })
121
-
122
- setImmediate(function () {
123
- feed.append(['c', 'd', 'e'])
124
- })
125
- })
126
- })
127
- }
128
-
129
- tape('createWriteStream with maxBlockSize', function (t) {
130
- t.plan(11 * 2 + 1)
131
-
132
- var feed = create()
133
-
134
- var ws = feed.createWriteStream({ maxBlockSize: 100 * 1024 })
135
-
136
- ws.write(Buffer.alloc(1024 * 1024))
137
- ws.end(function () {
138
- t.same(feed.length, 11)
139
-
140
- sameSize(0, 100 * 1024)
141
- sameSize(1, 100 * 1024)
142
- sameSize(2, 100 * 1024)
143
- sameSize(3, 100 * 1024)
144
- sameSize(4, 100 * 1024)
145
- sameSize(5, 100 * 1024)
146
- sameSize(6, 100 * 1024)
147
- sameSize(7, 100 * 1024)
148
- sameSize(8, 100 * 1024)
149
- sameSize(9, 100 * 1024)
150
- sameSize(10, 1024 * 1024 - 10 * 100 * 1024)
151
-
152
- function sameSize (idx, size) {
153
- feed.get(idx, function (err, blk) {
154
- t.error(err, 'no error')
155
- t.same(blk.length, size)
156
- })
157
- }
158
- })
159
- })
160
-
161
- test()
162
- test(10)
package/test/timeouts.js DELETED
@@ -1,22 +0,0 @@
1
- const tape = require('tape')
2
- const create = require('./helpers/create')
3
-
4
- tape('get before timeout', function (t) {
5
- const feed = create()
6
-
7
- feed.get(0, { timeout: 100 }, function (err) {
8
- t.error(err, 'no timeout error')
9
- t.end()
10
- })
11
-
12
- feed.append('hi')
13
- })
14
-
15
- tape('get after timeout', function (t) {
16
- const feed = create()
17
-
18
- feed.get(42, { timeout: 100 }, function (err) {
19
- t.ok(err, 'had timeout')
20
- t.end()
21
- })
22
- })