This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree 2 files changed +4
-17
lines changed
2 files changed +4
-17
lines changed Original file line number Diff line number Diff line change 49
49
"multiaddr" : " ^5.0.0" ,
50
50
"multibase" : " ~0.4.0" ,
51
51
"multihashes" : " ~0.4.13" ,
52
+ "nanoid" : " ^1.2.3" ,
52
53
"ndjson" : " ^1.5.0" ,
53
54
"once" : " ^1.4.0" ,
54
55
"peer-id" : " ~0.11.0" ,
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
const { Duplex, Transform } = require ( 'stream' )
3
3
const isStream = require ( 'is-stream' )
4
+ const nanoid = require ( 'nanoid' )
4
5
const pump = require ( 'pump' )
5
6
const Multipart = require ( './multipart2' )
6
7
const { prepareWithHeaders } = require ( './../utils/prepare-file' )
7
8
8
9
const noop = ( ) => { }
9
- /**
10
- * Poor man's uuid
11
- *
12
- * @returns {String }
13
- */
14
- function uuid ( ) {
15
- function chr4 ( ) {
16
- return Math . random ( ) . toString ( 16 ) . slice ( - 4 )
17
- }
18
- return chr4 ( ) + chr4 ( ) +
19
- '-' + chr4 ( ) +
20
- '-' + chr4 ( ) +
21
- '-' + chr4 ( ) +
22
- '-' + chr4 ( ) + chr4 ( ) + chr4 ( )
23
- }
24
10
25
11
const prepareTransform = ( options ) => new Transform ( {
26
12
objectMode : true ,
@@ -41,7 +27,7 @@ class SendStream extends Duplex {
41
27
this . send = send
42
28
this . multipart = new Multipart ( options )
43
29
this . boundary = this . multipart . _boundary
44
- this . uuid = uuid ( )
30
+ this . uuid = nanoid ( )
45
31
this . index = 0
46
32
this . rangeStart = 0
47
33
this . rangeEnd = 0
@@ -118,7 +104,7 @@ class SendStream extends Duplex {
118
104
}
119
105
120
106
onData ( chunk ) {
121
- console . log ( 'Send ' , chunk . toString ( ) )
107
+ console . log ( 'Send ' , chunk . length )
122
108
// stop producing chunks
123
109
this . multipart . pauseAll ( )
124
110
this . extraBytes = this . multipart . extraBytes
You can’t perform that action at this time.
0 commit comments