ZLIB

ZLIB

Source:

This module provides helper WSH (Windows Script Host) functions that handle archiver apps (7-Zip and RAR).

Requires

Methods

(static) _createTmpListFile(paths, optionsopt) → {string}

Source:

Creates a temporary list file.

Parameters:
Name Type Attributes Description
paths Array.<string> | string

The file paths.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
encoding string <optional>
'utf8'

The character encoding.

eol string <optional>
'\n'

The character of EOL (end of line).

Returns:
  • The created temporary file path.
Type
string

(static) _makeDestArchivePath(ext, paths, destopt) → {string}

Source:

Makes An archive file path.

Parameters:
Name Type Attributes Description
ext string

The archive file extension (ex: ".zip")

paths Array.<string> | string

The archiving file paths.

dest string <optional>

A destination path.

Returns:
  • The created archive file path.
Type
string

(static) deflateSync(paths, destopt, optionsopt) → {typeDeflateResult|string}

Source:

Compresses and encrypts files into ZIP with 7-Zip.

Example
var zlib = Wsh.ZLIB; // Shorthand
var path = Wsh.Path;

var exe7z = path.join(__dirname, '.\\bin\\7-Zip\\7z.exe');

// Zipping a directory
var rtn = zlib.deflateSync('C:\\My Data', 'D:\\Backup.zip', {
  exe7z: exe7z
});

console.dir(rtn);
// Outputs:
// { command: "C:\My script\bin\7-Zip\7z.exe" u -tzip -ssw -r0 "D:\\Backup.zip" @"C:\Users\<Your Name>\AppData\Local\Temp\fs-writeTmpFileSync_rad3CD32.tmp"",
//   exitCode: 0,
//   stdout: "
// 7-Zip 22.00 (x64) : Copyright (c) 1999-2022 Igor Pavlov : 2022-06-15
// ...
// ..
// Everything is Ok
// ",
//   stderr: "",
//   error: false,
//   archivedPath: "D:\\Backup.zip" }

// With many options
var rtn = zlib.deflateSync('C:\\My Data\\*.txt', 'D:\\Backup.zip', {
  dateCode: 'yyyyMMdd-HHmmss',
  compressLv: 9,
  password: 'This is mY&p@ss ^_<',
  excludingFiles: ['*SJIS*'],
  includesSubDir: false,
  exe7z: exe7z
});

console.dir(rtn);
// Outputs:
// { command: "C:\My script\bin\7-Zip\7z.exe" u -tzip -ssw -r- -xr-@"C:\Users\<Your Name>\AppData\Local\Temp\fs-writeTmpFileSync_radD1C8B.tmp" -mx9 -p"This is mY&p@ss ^_<" -mem=AES256 "D:\\Backup_20220722-100513.zip" @"C:\Users\<Your Name>\AppData\Local\Temp\fs-writeTmpFileSync_radA1BD8.tmp"",
//   exitCode: 0,
//   stdout: "
// 7-Zip 22.00 (x64) : Copyright (c) 1999-2022 Igor Pavlov : 2022-06-15
// ...
// ..
// Files read from disk: 5
// Archive size: 2291 bytes (3 KiB)
// Everything is Ok
// ",
//   stderr: "",
//   error: false,
//   archivedPath: "D:\\Backup_20220722-100513.zip" }
Parameters:
Name Type Attributes Description
paths Array.<string> | string

The compressed file paths. If a directory is specified, all of them are compressed, including sub directories. If you use a wildcard to specify the paths, you can use the R option to control the files contained in the sub directories.

dest string <optional>

The filepath or directory of destination ZIP.

options typeDeflateZipOption <optional>

Optional parameters.

Returns:
  • See typeDeflateResult. If options.isDryRun is true, returns string.
Type
typeDeflateResult | string

(static) deflateSyncIntoRar(paths, destopt, optionsopt) → {typeDeflateResult|string}

Source:

Compresses and encrypts files into RAR.

Example
var zlib = Wsh.ZLIB; // Shorthand
var path = Wsh.Path;

var dirWinRar = path.join(__dirname, '.\\bin\\WinRar');

// Archiving a directory as a Rar file
var rtn = zlib.deflateSyncIntoRar('C:\\My Data', 'D:\\Backup.rar', {
  dirWinRar: dirWinRar
});

console.dir(rtn);
// Outputs:
// { command: "C:\My Script\bin\WinRAR\Rar.exe" a -u -o+ -r0 -dh -ep1 -m3 -ma5 -os -s -y "D:\Backup.rar" @"C:\Users\Your Name\AppData\Local\Temp\fs-writeTmpFileSync_radB5E4E.tmp"",
//   exitCode: 0,
//   stdout: "
// RAR 6.11 x64   Copyright (c) 1993-2022 Alexander Roshal   3 Mar 2022
// ...
// ..
// Done
// ",
//   stderr: "",
//   error: false,
//   archivedPath: "D:\\Backup.rar" }

// With many options
var rtn = zlib.deflateSyncIntoRar('C:\\My Data\\*.txt', 'D:\\Backup.rar', {
  dateCode: 'yyyyMMdd-HHmmss',
  compressLv: 0,
  password: 'This is mY&p@ss ^_<',
  excludingFiles: ['*utf16*', 'settings.json'],
  excludesEmptyDir: true,
  excludesSubDirWildcard: true,
  isGUI: true,
  dirWinRar: dirWinRar
});

console.dir(rtn);
// Outputs:
// { command: "C:\My Script\bin\WinRAR\WinRar.exe" a -u -o+ -x@"C:\Users\<Your Name>\AppData\Local\Temp\fs-writeTmpFileSync_rad017F1.tmp" -dh -ed -ep1 -m0 -hp"This is mY&p@ss ^_<" -ma5 -os -s -y "D:\Backup_20220722-103741.rar" @"C:\Users\<Your Name>\AppData\Local\Temp\fs-writeTmpFileSync_rad89C8F.tmp",
//  exitCode: 0,
//  stdout: "",
//  stderr: "",
//  error: false,
//  archivedPath: "D:\Backup_20220722-103741.rar" }
Parameters:
Name Type Attributes Description
paths Array.<string> | string

The compressed file paths. If a directory is specified, all of them are compressed, including sub directories. If you use a wildcard to specify the paths, you can use the R option to control the files contained in the sub directories.

dest string <optional>

The filepath or directory of destination ZIP.

options typeDeflateRarOption <optional>

Optional parameters.

Returns:
  • @see typeDeflateResult. If options.isDryRun is true, returns string.
Type
typeDeflateResult | string

(static) openRar(archive, optionsopt) → {void}

Source:

Opens the RAR file.

Example
var zlib = Wsh.ZLIB; // Shorthand
var path = Wsh.Path;
var dirWinRar = path.join(__dirname, '.\\bin\\WinRar');

zlib.openRar('D:\\Backup.rar', { dirWinRar: dirWinRar });
Parameters:
Name Type Attributes Description
archive string

An archive filepath

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
dirWinRar string <optional>
DEF_DIR_WINRAR

A custom directory path of WinRAR.

winStyle string <optional>
'activeDef'
Returns:
Type
void

(static) openZip(archive, optionsopt) → {void}

Source:

Open the archive file with 7-Zip.

Parameters:
Name Type Attributes Description
archive string

An archive filepath

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
exe7zFM string <optional>
DEF_7ZFM_EXE

A custom .exe path of 7-ZIP file manager.

winStyle string <optional>
'activeDef'
Returns:
Type
void

(static) testRarSync(archive, optionsopt) → {object|string}

Source:

Test RAR file

Parameters:
Name Type Attributes Description
archive string

The archive file path to open.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
dirWinRar string <optional>
DEF_DIR_WINRAR

A custom directory path of WinRAR.

isGUI boolean <optional>
false

true:WinRar.exe false:Rar.exe

outputsLog boolean <optional>
false

Output console logs.

Returns:
Type
object | string

(static) unrarSync(archive, destDiropt, optionsopt) → {object}

Source:

Extracts files from archiver with Rar.

Example
var zlib = Wsh.ZLIB; // Shorthand
var path = Wsh.Path;
var dirWinRar = path.join(__dirname, '.\\bin\\WinRar');

var rtn = zlib.unrarSync('D:\\Backup.rar', 'C:\\Temp', {
  makesArchiveNameDir: true,
  dirWinRar: dirWinRar;
});
Parameters:
Name Type Attributes Description
archive string

An archive file path

destDir string <optional>

A output directory path.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
dirWinRar string <optional>
DEF_DIR_WINRAR

A custom directory path of WinRAR.

isGUI boolean <optional>
true

true:WinRar.exe false:Rar.exe

password string <optional>
makesArchiveNameDir boolean <optional>
false

Make a new directory with archive file name

outputsLog boolean <optional>
false

Output console logs.

isDryRun boolean <optional>
false

No execute, returns the string of command.

Returns:
Type
object

(static) unzipSync(archive, destDiropt, optionsopt) → {object}

Source:

Extract files from an archive with 7-Zip.

Parameters:
Name Type Attributes Description
archive string

The archive file path

destDir string <optional>

The output directory path.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
exe7z string <optional>
DEF_7ZIP_EXE

A custom .exe path of 7-ZIP.

password string <optional>

Specifies password.

workingDir string <optional>

Working directory

makesDestDir boolean <optional>
false

Makes the destination directory. If it is not existing.

makesArchiveNameDir boolean <optional>
false

Makes a new directory with archive file name

outputsLog boolean <optional>
false

Output console logs.

isDryRun boolean <optional>
false

No execute, returns the string of command.

Returns:
Type
object