make-mega
Advanced tools
Comparing version 0.1.41 to 0.2.0
35
index.js
const fs = require("fs"), | ||
mb = 1000000, | ||
oneMega = require('./one-mega'), | ||
size = process.argv[2] || 100; | ||
let content = "0"; | ||
function main() { | ||
try { | ||
if (size > 700) | ||
throw new Error("Sorry, I can only make files up to 700mb."); | ||
console.log("Generating base string..."); | ||
while (content.length < size * mb) { | ||
let additive = content; | ||
if (additive.length > mb * 600) additive = additive.substring(0, 10 * mb); | ||
if (additive.length > mb * 500) additive = additive.substring(0, 50 * mb); | ||
content = `${content}${additive}`; | ||
} | ||
console.log(`Trimming to ${size}mb...`); | ||
const offset = content.length - mb * size; | ||
content = content.substring(0, content.length - offset); | ||
console.log(`Attempting to write...`); | ||
// eslint-disable-next-line node/prefer-promises/fs | ||
fs.writeFile( | ||
Math.floor(content.length / 1000 / 1000) + "-mb.txt", | ||
content, | ||
error => { | ||
if (error) throw error; | ||
console.log(`${size}mb file successfully created.`); | ||
} | ||
); | ||
const stream = fs.createWriteStream(size + "-mb.txt", { flags: 'a'}); | ||
[...Array(size)].forEach(function(item, index) { | ||
stream.write(oneMega); | ||
}) | ||
stream.end(); | ||
console.log(`${size}mb file successfully created.`); | ||
} catch ({ message }) { | ||
@@ -39,2 +20,4 @@ console.log(message); | ||
main(); | ||
module.exports = main; |
{ | ||
"name": "make-mega", | ||
"version": "0.1.41", | ||
"version": "0.2.0", | ||
"description": "Make large files for testing in increments of one megabyte. ", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -24,1 +24,4 @@ # make-mega | ||
``` | ||
## Releases | ||
* 0.2.0 - Change to using a stream to append the data to the file. This should remove the previous file size limitations. |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
105909105
7
4123
26
1