disk-cleanup
Version:
This project offers a set of functions to perform disk cleanup operations in Node.js, including backup creation, restoration, and removal of files and directories.
167 lines (149 loc) • 5.47 kB
HTML
<h1>disk-cleanup</h1>
<p>This project offers a set of functions to perform disk cleanup operations in Node.js, including backup creation, restoration, and removal of files and directories.</p>
<h2>Prerequisites:</h2>
<ul>
<li>Make sure you have Node.js installed on your system.</li>
</ul>
<h2>Installation:</h2>
<pre><code class="language-bash"> npm install disk-cleanup
</code></pre>
<h2>Usage:</h2>
<blockquote>
<blockquote>
<p><em><strong>Removing Temporary Files</strong></em></p>
</blockquote>
</blockquote>
<ul>
<li>
<p>The removeTemporary function is used to delete temporary files from a specified directory.</p>
</li>
<li>
<pre><code class="language-js"> const diskCleanup = require('disk-cleanup');
diskCleanup.removeTemporary('/path/to/directory', (err, result) => {
if (err) {
console.error('Error:', err);
} else {
console.log('Result:', result);
}
});
</code></pre>
</li>
</ul>
<blockquote>
<blockquote>
<p><em><strong>Backup and Restore</strong></em></p>
</blockquote>
</blockquote>
<ul>
<li>
<p>This package also offers backup and restore functionalities.</p>
<p>*<strong>const diskCleanup = require('disk-cleanup');</strong></p>
<p>*<strong>const backupPath = diskCleanup.createBackupDirectory('/path/to/directory');</strong></p>
<ul>
<li>this function will create a backup directory inside the directory given by you.</li>
<li>If path of directory is not given than backup directory will be created in current working directory.</li>
<li>console.log('Backup directory created at:', backupPath);</li>
</ul>
<p>*<strong>diskCleanup.backupFile("/path/of/file","/path/of/backup directory");</strong></p>
<ul>
<li>this function will backup a file you provided by path inside backup directory path you provided.</li>
<li>if path of backup directory is not given it will search for backup directory in current working directory/</li>
</ul>
<p>*<strong>diskCleanup.restoreBackup( "filename","backupPath", "dirPath");</strong></p>
<ul>
<li>restore the backup file</li>
<li><em><strong>backuppath-</strong></em> backup directory path inside which the file is saved or backup.</li>
<li><em><strong>filename-</strong></em> the name of file</li>
<li><em><strong>dirpath-</strong></em> path of directory where you want to restore</li>
<li>If backup path is not given than it will search for backup directory in you current working directory</li>
<li>if dirPath is not given than it will also restore the files in the current working directory.</li>
</ul>
<p>*<strong>diskCleanup.removeBackupFile( "fileName", "backupPath");</strong></p>
<ul>
<li>removes the backup file</li>
<li><em><strong>backuppath-</strong></em> this is the path of backup directory</li>
<li><em><strong>filename-</strong></em> file name u want to delete</li>
<li>If backupPath is not given than it will search for backup directory in current working directory</li>
</ul>
<p>*<strong>diskCleanup.removeBackupdir("backupPath");</strong></p>
<ul>
<li>remove the backup directory all the backup will be deleted</li>
<li><em><strong>backuppath-</strong></em> path of backup directory you want to delete</li>
<li>If backupPath is not given than it will search for backup directory in current working directory</li>
</ul>
</li>
</ul>
<blockquote>
<blockquote>
<p><em><strong>Filter by File Size</strong></em></p>
</blockquote>
</blockquote>
<ul>
<li>
<pre><code class="language-js">
const diskCleanup = require('disk-cleanup');
//size will given in the bytes in all functions
// Deletes files of a specified size from a given directory.
diskCleanup.filterEqual('/path/to/directory', size, (err, result) => {
if (err) {
console.error('Error:', err);
} else {
console.log('Result:', result);
}
});
//Deletes files greater than a specified size from a given directory.
diskCleanup.filterGreater('/path/to/directory', size, (err, result) => {
if (err) {
console.error('Error:', err);
} else {
console.log('Result:', result);
}
});
//Deletes files smaller than a specified size from a given directory.
diskCleanup.filterSmaller('/path/to/directory', size, (err, result) => {
if (err) {
console.error('Error:', err);
} else {
console.log('Result:', result);
}
});
//if u know size not in bytes than you can simply convert by functions:
diskCleanup.filterSmaller('/path/to/directory', kb_to_bytes(size in bytes), (err, result) => {
if (err) {
console.error('Error:', err);
} else {
console.log('Result:', result);
}
});
</code></pre>
</li>
</ul>
<blockquote>
<blockquote>
<p><em><strong>Size conversion</strong></em></p>
</blockquote>
</blockquote>
<ul>
<li>convert the data size into bytes usefull for filtering functions.</li>
<li>
<pre><code class="language-js">
kb_to_bytes(20) // convert 20 kb into bytes
mb_to_bytes(20) //20 mb to bytes
gb_to_bytes(10)
tb_to_bytes(20)
pb_to_bytes(20)
eb_to_bytes(20)
zb_to_bytes(20)
yb_to_bytes(20)
</code></pre>
</li>
</ul>
<h2>Contributing:</h2>
<ul>
<li>Contributions are welcome! Please feel free to submit issues or pull requests.</li>
</ul>
<h2>License</h2>
<ul>
<li>This project is licensed under the MIT License.</li>
<li>Feel free to modify or expand the README further based on your preferences or any additional information you wish to provide!</li>
</ul>