New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@fknop/node-unrar

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fknop/node-unrar - npm Package Compare versions

Comparing version 1.0.5 to 1.1.0

8

lib/index.d.ts

@@ -10,7 +10,10 @@ /// <reference types="es6-promise" />

dest?: string;
recursiveResults?: boolean;
humanResults?: boolean;
}
export interface HRFiles {
[key: string]: HRFiles;
}
export interface RarResult {
name: string;
files: string[];
files: string[] | HRFiles;
}

@@ -21,2 +24,3 @@ export interface FileEntry {

export declare type RarCallback = (err: any, result: RarResult) => void;
export declare function processFiles(files: string[]): HRFiles;
export declare function processArchive(path: string, options?: RarOptions | RarCallback, cb?: RarCallback): Promise<RarResult> | void;

@@ -23,0 +27,0 @@ export declare function list(path: string, options?: RarOptions | RarCallback, cb?: RarCallback): Promise<RarResult> | void;

@@ -22,19 +22,22 @@ "use strict";

}
// TODO
function getFilesMap(files) {
var map = {};
files.forEach(function (file) {
var split = file.split(Path.sep);
var previous = map;
var current;
for (var i = 0; i < split.length; ++i) {
current = split[i];
if (!previous[current]) {
previous[current] = {};
}
previous = previous[current];
}
});
return map;
}
function processFiles(files) {
var results = [];
//
/*{
entries: [
file,
dir: [
file,
dir: [
]
]
]
}
*/
return getFilesMap(files);
}
exports.processFiles = processFiles;
function processArchive(path, options, cb) {

@@ -56,3 +59,13 @@ var realpath = Path.resolve(path);

}
unrar.processArchive(opts, cb);
unrar.processArchive(opts, function (err, result) {
if (err) {
cb(err, null);
}
else {
if (opts.humanResults) {
result.files = processFiles(result.files);
}
cb(null, result);
}
});
}

@@ -59,0 +72,0 @@ exports.processArchive = processArchive;

@@ -16,8 +16,12 @@ import * as Path from 'path';

dest?: string;
recursiveResults?: boolean;
humanResults?: boolean;
}
export interface HRFiles {
[key: string]: HRFiles;
}
export interface RarResult {
name: string;
files: string[];
files: string[]|HRFiles;
}

@@ -41,22 +45,31 @@

// TODO
function processFiles (files: string[]) {
function getFilesMap (files: string[]): HRFiles {
const results: FileEntry[] = []
const map: HRFiles = {};
//
/*{
entries: [
file,
dir: [
file,
dir: [
files.forEach((file: string) => {
]
]
]
}
*/
const split = file.split(Path.sep);
let previous: HRFiles = map;
let current: string;
for (let i = 0; i < split.length; ++i) {
current = split[i];
if (!previous[current]) {
previous[current] = {};
}
previous = previous[current];
}
});
return map;
}
export function processFiles (files: string[]): HRFiles {
return getFilesMap(files);
}
export function processArchive (path: string, options?: RarOptions|RarCallback, cb?: RarCallback): Promise<RarResult>|void {

@@ -86,3 +99,14 @@

unrar.processArchive(opts, cb);
unrar.processArchive(opts, (err: any, result: RarResult) => {
if (err) {
cb(err, null);
}
else {
if (opts.humanResults) {
result.files = processFiles(<string[]>result.files);
}
cb(null, result);
}
});
}

@@ -89,0 +113,0 @@

{
"name": "@fknop/node-unrar",
"version": "1.0.5",
"version": "1.1.0",
"description": "Native NodeJS rar addon",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -5,9 +5,14 @@ # node-rar

This library is inspired by https://github.com/davidcroda/node-rar.
The library (`davidcroda/node-rar`) has not been updated for latest versions of NodeJS.
This repository also works asynchronously.
This library is inspired by https://github.com/davidcroda/node-rar and the original library.
I needed a native unrar addon that worked with the new versions of node.
I also updated the addon to be able to process an archive `asynchronously`.
This is still a work in progress.
## Install
```
npm install @fknop/node-unrar
```
It's published under the @fknop scope to avoid using a name like `node-unrar2` or something like that.
## API

@@ -30,3 +35,3 @@

* `password`: the archive password
* `humanResults`: (not yet implemented) - instead of an array of raw string names, display the files as a tree
* `humanResults`: instead of an array of raw string names, display the files as a tree

@@ -55,14 +60,14 @@ Without `humanResults`:

name: 'archive.rar',
files: [
'dir': [
'file1',
'file2',
'file3',
'dir2': [
'file4',
'file5'
]
],
'file'
]
files: {
'dir': {
'file1': {},
'file2': {},
'file3': {},
'dir2': {
'file4': {},
'file5': {}
}
},
'file': {}
}
}

@@ -105,1 +110,5 @@ ```

Alias for `processArchiveSync` with `OpenMode.Extract`.
## Todo
* Tests

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