Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

addon-tools-raub

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

addon-tools-raub - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

utils.js

37

cpbin.js
'use strict';
const fs = require('fs');
const { copy, exists, mkdir, rm } = require('./utils');
const { bin } = require('.');
const copy = (src, dest) => new Promise(
(res, rej) => fs.copyFile(src, dest, err => (err ? rej(err) : res()))
);
const exists = name => new Promise(
res => fs.access(
name,
fs.constants.F_OK,
err => res(err ? false : true)
)
);
const mkdir = async name => {
if (await exists(name)) {
return;
}
return new Promise(
(res, rej) => fs.mkdir(name, err => (err ? rej(err) : res()))
);
};
const rm = async name => {
if ( ! await exists(name) ) {
return;
}
await new Promise(
(res, rej) => fs.unlink(name, err => (err ? rej(err) : res()))
);
};
module.exports = async name => {

@@ -43,0 +8,0 @@

@@ -6,6 +6,8 @@ 'use strict';

const http = require('http');
const fs = require('fs');
const unzipper = require('unzipper');
const AdmZip = require('adm-zip');
const { bin, platform } = require('.');
const { mkdir, rm } = require('./utils');

@@ -20,9 +22,16 @@

const zipPath = `${bin}/${bin}.zip`;
const install = (url, count = 1) => {
const proto = protocols[url.match(/^https?/)[0]];
const request = proto.get(url, response => {
const install = async (url, count = 1) => {
try {
const proto = protocols[url.match(/^https?/)[0]];
const response = await new Promise((res, rej) => {
const request = proto.get(url, response => res(response));
request.on('error', err => rej(err));
});
response.on('error', err => { throw err; });
// Handle redirects

@@ -34,3 +43,3 @@ if ([301, 302, 303, 307].includes(response.statusCode)) {

console.log(url);
return onError('Error: Too many redirects.');
throw new Error('Error: Too many redirects.');
}

@@ -41,16 +50,23 @@

console.log(url);
return onError(`Response status was ${response.statusCode}`);
throw new Error(`Response status was ${response.statusCode}`);
}
response.on('error', err => onError(err.message));
await mkdir(bin);
const extractor = unzipper.Extract({ path: bin });
extractor.on('error', err => onError(err.message));
await new Promise((res, rej) => {
const zipWriter = fs.createWriteStream(zipPath);
zipWriter.on('error', err => rej(err));
zipWriter.on('finish', () => res());
response.pipe(zipWriter);
});
response.pipe(extractor);
const zip = new AdmZip(zipPath);
zip.extractAllTo(bin, true);
});
await rm(zipPath);
} catch (ex) {
onError(ex.message);
}
request.on('error', err => onError(err.message));
};

@@ -61,3 +77,3 @@

const url = `${folder}/${platform}.zip`;
install(url);
install(url).then();
};
{
"author": "Luis Blanco <luisblanco1337@gmail.com>",
"name": "addon-tools-raub",
"version": "5.0.0",
"version": "5.1.0",
"description": "Helpers for Node.js addons and dependency packages",

@@ -26,2 +26,3 @@ "license": "MIT",

"install.js",
"utils.js",
"writable-buffer.js",

@@ -41,5 +42,5 @@ "LICENSE",

"dependencies": {
"node-addon-api": "1.7.1",
"unzipper": "0.10.5"
"adm-zip": "0.4.14",
"node-addon-api": "2.0.0"
}
}

@@ -120,1 +120,23 @@ # Addon Tools

```
## utils.js
* `read` - (async) Reads a whole file to string, NOT A Buffer.
* `write` - (async) Write a file.
* `copy` - (async) Copy a file.
* `exists` - (async) Check if a file/folder exists.
* `mkdir` - (async) Create an empty folder.
* `stat` - (async) Get status on a file.
* `isDir` - (async) Check if the path is a folder.
* `isFile` - (async) Check if the path is a file.
* `dirUp` - Cut the path one folder up.
* `ensuredir` - (async) Like `mkdir -p`, makes sure a directory exists.
* `copysafe` - (async) Copy a file, `dest` folder is created if needed.
* `readdir` - (async) Get file/folder names of the 1st level.
* `subdirs` - (async) Get folder paths (concatenated with input) of the 1st level.
* `subfiles` - (async) Get file paths (concatenated with input) of the 1st level.
* `traverse` - (async) Get all nested files recursively.
* `copyall` - (async) Copy a folder with all the contained files.
* `rmdir` - (async) Like `rm -rf`, removes everything recursively.
* `rm` - (async) Remove a file. Must be a file, not a folder. Just `fs.unlink`.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc