Skip to content

Commit

Permalink
Remove deprecated flatten dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Aug 2, 2019
1 parent f83c8db commit 0eab275
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const BlockStream = require('block-stream2')
const calcPieceLength = require('piece-length')
const corePath = require('path')
const FileReadStream = require('filestream/read')
const flatten = require('flatten')
const fs = require('fs')
const isFile = require('is-file')
const junk = require('junk')
Expand All @@ -13,6 +12,16 @@ const parallel = require('run-parallel')
const sha1 = require('simple-sha1')
const stream = require('readable-stream')

// TODO: When Node 10 support is dropped, replace this Array.prototype.flat
function flat (arr1) {
return arr1.reduce(
(acc, val) => Array.isArray(val)
? acc.concat(flat(val))
: acc.concat(val),
[]
)
}

const announceList = [
['udp://tracker.leechers-paradise.org:6969'],
['udp://tracker.coppersurfer.tk:6969'],
Expand Down Expand Up @@ -192,7 +201,7 @@ function _parseInput (input, opts, cb) {
cb(null, file)
}), (err, files) => {
if (err) return cb(err)
files = flatten(files)
files = flat(files)
cb(null, files, isSingleFileTorrent)
})
}
Expand All @@ -202,7 +211,7 @@ function getFiles (path, keepRoot, cb) {
traversePath(path, getFileInfo, (err, files) => {
if (err) return cb(err)

if (Array.isArray(files)) files = flatten(files)
if (Array.isArray(files)) files = flat(files)
else files = [files]

path = corePath.normalize(path)
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"bencode": "^2.0.0",
"block-stream2": "^2.0.0",
"filestream": "^5.0.0",
"flatten": "^1.0.2",
"is-file": "^1.0.0",
"junk": "^3.1.0",
"minimist": "^1.1.0",
Expand Down

0 comments on commit 0eab275

Please sign in to comment.