Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 300af44

Browse files
committed
fix: use nanoid for uuid
1 parent d58e8cb commit 300af44

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"multiaddr": "^5.0.0",
5050
"multibase": "~0.4.0",
5151
"multihashes": "~0.4.13",
52+
"nanoid": "^1.2.3",
5253
"ndjson": "^1.5.0",
5354
"once": "^1.4.0",
5455
"peer-id": "~0.11.0",

src/add2/send-stream.js

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
'use strict'
22
const { Duplex, Transform } = require('stream')
33
const isStream = require('is-stream')
4+
const nanoid = require('nanoid')
45
const pump = require('pump')
56
const Multipart = require('./multipart2')
67
const { prepareWithHeaders } = require('./../utils/prepare-file')
78

89
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-
}
2410

2511
const prepareTransform = (options) => new Transform({
2612
objectMode: true,
@@ -41,7 +27,7 @@ class SendStream extends Duplex {
4127
this.send = send
4228
this.multipart = new Multipart(options)
4329
this.boundary = this.multipart._boundary
44-
this.uuid = uuid()
30+
this.uuid = nanoid()
4531
this.index = 0
4632
this.rangeStart = 0
4733
this.rangeEnd = 0
@@ -118,7 +104,7 @@ class SendStream extends Duplex {
118104
}
119105

120106
onData (chunk) {
121-
console.log('Send ', chunk.toString())
107+
console.log('Send ', chunk.length)
122108
// stop producing chunks
123109
this.multipart.pauseAll()
124110
this.extraBytes = this.multipart.extraBytes

0 commit comments

Comments
 (0)