@@ -10,6 +10,7 @@ const id = require('hypercore-id-encoding')
1010const safetyCatch = require ( 'safety-catch' )
1111const unslab = require ( 'unslab' )
1212
13+ const inspect = require ( './lib/inspect' )
1314const Core = require ( './lib/core' )
1415const Info = require ( './lib/info' )
1516const Download = require ( './lib/download' )
@@ -29,7 +30,7 @@ const {
2930 DECODING_ERROR
3031} = require ( 'hypercore-errors' )
3132
32- const inspect = Symbol . for ( 'nodejs.util.inspect.custom' )
33+ const inspectSymbol = Symbol . for ( 'nodejs.util.inspect.custom' )
3334
3435// Hypercore actually does not have any notion of max/min block sizes
3536// but we enforce 15mb to ensure smooth replication (each block is transmitted atomically)
@@ -96,92 +97,8 @@ class Hypercore extends EventEmitter {
9697 this . on ( 'newListener' , maybeAddMonitor )
9798 }
9899
99- [ inspect ] ( depth , opts ) {
100- let indent = ''
101- if ( typeof opts . indentationLvl === 'number' ) {
102- while ( indent . length < opts . indentationLvl ) indent += ' '
103- }
104-
105- let peers = ''
106- const min = Math . min ( this . peers . length , 5 )
107-
108- for ( let i = 0 ; i < min ; i ++ ) {
109- const peer = this . peers [ i ]
110-
111- peers += indent + ' Peer(\n'
112- peers +=
113- indent +
114- ' remotePublicKey: ' +
115- opts . stylize ( toHex ( peer . remotePublicKey ) , 'string' ) +
116- '\n'
117- peers += indent + ' remoteLength: ' + opts . stylize ( peer . remoteLength , 'number' ) + '\n'
118- peers += indent + ' remoteFork: ' + opts . stylize ( peer . remoteFork , 'number' ) + '\n'
119- peers +=
120- indent + ' remoteCanUpgrade: ' + opts . stylize ( peer . remoteCanUpgrade , 'boolean' ) + '\n'
121- peers += indent + ' )' + '\n'
122- }
123-
124- if ( this . peers . length > 5 ) {
125- peers += indent + ' ... and ' + ( this . peers . length - 5 ) + ' more\n'
126- }
127-
128- if ( peers ) peers = '[\n' + peers + indent + ' ]'
129- else peers = '[ ' + opts . stylize ( 0 , 'number' ) + ' ]'
130-
131- return (
132- this . constructor . name +
133- '(\n' +
134- indent +
135- ' id: ' +
136- opts . stylize ( this . id , 'string' ) +
137- '\n' +
138- indent +
139- ' key: ' +
140- opts . stylize ( toHex ( this . key ) , 'string' ) +
141- '\n' +
142- indent +
143- ' discoveryKey: ' +
144- opts . stylize ( toHex ( this . discoveryKey ) , 'string' ) +
145- '\n' +
146- indent +
147- ' opened: ' +
148- opts . stylize ( this . opened , 'boolean' ) +
149- '\n' +
150- indent +
151- ' closed: ' +
152- opts . stylize ( this . closed , 'boolean' ) +
153- '\n' +
154- indent +
155- ' snapshotted: ' +
156- opts . stylize ( this . snapshotted , 'boolean' ) +
157- '\n' +
158- indent +
159- ' writable: ' +
160- opts . stylize ( this . writable , 'boolean' ) +
161- '\n' +
162- indent +
163- ' length: ' +
164- opts . stylize ( this . length , 'number' ) +
165- '\n' +
166- indent +
167- ' fork: ' +
168- opts . stylize ( this . fork , 'number' ) +
169- '\n' +
170- indent +
171- ' sessions: [ ' +
172- opts . stylize ( this . sessions . length , 'number' ) +
173- ' ]\n' +
174- indent +
175- ' activeRequests: [ ' +
176- opts . stylize ( this . activeRequests . length , 'number' ) +
177- ' ]\n' +
178- indent +
179- ' peers: ' +
180- peers +
181- '\n' +
182- indent +
183- ')'
184- )
100+ [ inspectSymbol ] ( depth , opts ) {
101+ return inspect ( this , depth , opts )
185102 }
186103
187104 static MAX_SUGGESTED_BLOCK_SIZE = MAX_SUGGESTED_BLOCK_SIZE
@@ -442,17 +359,12 @@ class Hypercore extends EventEmitter {
442359 throw ASSERTION ( 'Checkouts must be named or atomized' , this . discoveryKey )
443360 if ( checkout > this . state . length )
444361 throw ASSERTION (
445- ' Invalid checkout ' + checkout + ' for ' + opts . name + ' , length is ' + this . state . length ,
362+ ` Invalid checkout ${ checkout } for ${ opts . name } , length is ${ this . state . length } ` ,
446363 this . discoveryKey
447364 )
448365 if ( this . state . prologue && checkout < this . state . prologue . length ) {
449366 throw ASSERTION (
450- 'Invalid checkout ' +
451- checkout +
452- ' for ' +
453- opts . name +
454- ', prologue length is ' +
455- this . state . prologue . length ,
367+ `Invalid checkout ${ checkout } for ${ opts . name } , prologue length is ${ this . state . prologue . length } ` ,
456368 this . discoveryKey
457369 )
458370 }
@@ -1165,10 +1077,6 @@ function isStream(s) {
11651077 return typeof s === 'object' && s && typeof s . pipe === 'function'
11661078}
11671079
1168- function toHex ( buf ) {
1169- return buf && b4a . toString ( buf , 'hex' )
1170- }
1171-
11721080async function preappend ( blocks ) {
11731081 const offset = this . state . length
11741082 const fork = this . state . encryptionFork
0 commit comments