Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Get total diskspace and free diskspace using bindings around platform specific calls.
The diskusage npm package is used to retrieve disk usage information for a given path. It provides a simple interface to get the total, free, and available disk space on a filesystem.
Get Disk Usage Information
This feature allows you to check the disk usage of a specified path. The code sample demonstrates how to use the diskusage package to get the total, free, and available disk space for the root directory.
const disk = require('diskusage');
// Path to check disk usage
const path = '/';
disk.check(path, (err, info) => {
if (err) {
console.error(err);
} else {
console.log(`Total: ${info.total}`);
console.log(`Free: ${info.free}`);
console.log(`Available: ${info.available}`);
}
});
The check-disk-space package provides similar functionality to diskusage by allowing users to check the disk space of a specified path. It is easy to use and provides a promise-based API, which can be more convenient for modern JavaScript applications compared to the callback-based API of diskusage.
The diskspace package offers disk space information retrieval similar to diskusage. It supports both Windows and Unix-based systems and provides a simple API to get disk space details. However, it may not be as actively maintained as some other alternatives.
This module implements platform specific bindings to obtain disk usage information on Windows and POSIX platforms. Windows support is backed by GetDiskFreeSpaceEx and POSIX is implemented with statvfs.
Install with npm
:
$ npm install diskusage
The module exposes two functions. check
takes a path/mount point as the first argument and a callback as the second. The callback takes two arguments err
and info
. err
will be an Error
if something went wrong. info
contains three members: available
, free
and total
in bytes.
If no callback is supplied check
will instead return a Promise<DiskUsage>
that you can await.
available
: Disk space available to the current user (i.e. Linux reserves 5% for root)free
: Disk space physically freetotal
: Total disk space (free + used)checkSync
only takes the path argument. It returns the same info
on success, throws an Error
on failure.
const disk = require('diskusage');
const os = require('os');
let path = os.platform() === 'win32' ? 'c:' : '/';
// Callbacks
disk.check(path, function(err, info) {
if (err) {
console.log(err);
} else {
console.log(info.available);
console.log(info.free);
console.log(info.total);
}
});
// Promise
async function getFreeSpace(path) {
try {
const { free } = await disk.check(path);
console.log(`Free space: ${free}`);
return free
} catch (err) {
console.error(err)
return 0
}
}
// Or without using async/await
disk.check(path)
.then(info => console.log(`free: ${info.free}`))
.catch(err => console.error(err))
// Synchronous
try {
let info = disk.checkSync(path);
console.log(info.available);
console.log(info.free);
console.log(info.total);
}
catch (err) {
console.log(err);
}
The module has an embedded .d.ts file. You can use import * as diskusage from 'diskusage'
.
type DiskUsage = {
available: number;
free: number;
total: number;
}
export function check(path: string, callback: (error?: Error, result?: DiskUsage) => void): void;
export function check(path: string): Promise<DiskUsage>
export function checkSync(path: string): DiskUsage;
To see a demo of this library see the demo/
folder.
You can run it with node: (node 8+ required)
node ./demo/
FAQs
Get total diskspace and free diskspace using bindings around platform specific calls.
The npm package diskusage receives a total of 105,198 weekly downloads. As such, diskusage popularity was classified as popular.
We found that diskusage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.