diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-28 11:43:44 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-28 11:43:44 +0100 |
commit | 324fbb2f695a7efb012eb04e1184248cae960587 (patch) | |
tree | 516261eca635fe9eaa5563648e660c5538b4042c /lib/utils/fs.js | |
parent | 5539ab48a5e4cc5a94c692f62f2e9dc55d6a4e49 (diff) | |
download | gitbook-324fbb2f695a7efb012eb04e1184248cae960587.zip gitbook-324fbb2f695a7efb012eb04e1184248cae960587.tar.gz gitbook-324fbb2f695a7efb012eb04e1184248cae960587.tar.bz2 |
Convert svg images to png in ebook
Diffstat (limited to 'lib/utils/fs.js')
-rw-r--r-- | lib/utils/fs.js | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/utils/fs.js b/lib/utils/fs.js index 8d8c189..e434953 100644 --- a/lib/utils/fs.js +++ b/lib/utils/fs.js @@ -43,9 +43,27 @@ var fsUtils = { }, existsSync: fs.existsSync.bind(fs), readFileSync: fs.readFileSync.bind(fs), - clean: cleanFolder + clean: cleanFolder, + getUniqueFilename: getUniqueFilename } +// Find a filename available +function getUniqueFilename(base) { + var ext = path.extname(base); + base = path.join(path.dirname(base), path.basename(base, ext)); + + var filename = base+ext; + + var i = 0; + while (1) { + if (!fs.existsSync(filename)) break; + filename = base+"_"+i+ext; + i = i + 1; + } + + return filename; +}; + // List files in a directory function listFiles(root, options) { @@ -112,7 +130,7 @@ function cleanFolder(root) { var _file = path.join(root, file); d.notify({ - i: i, + i: i+1, count: files.length, file: _file }); |