UNPKG

667 BJavaScriptView Raw
1/**
2 * @module helpers
3 * @returns {Promise}
4 */
5
6'use strict'
7
8const fs = require('fs')
9
10const isStream = (content) => !!content && typeof content !== 'string' && !!content.pipe
11
12async function hasDuplicate (filename, content) {
13 if (isStream(content)) {
14 return false
15 }
16 const exists = await new Promise((resolve) =>
17 fs.exists(filename, (exists) => resolve(exists))
18 )
19 if (!exists) {
20 return false
21 }
22 const existing = await new Promise((resolve, reject) =>
23 fs.readFile(filename, (err, content) =>
24 err ? reject(err) : resolve(content)
25 )
26 )
27 return String(existing) === String(content)
28}
29
30module.exports = {hasDuplicate, isStream}