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

@absolunet/fss

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@absolunet/fss - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

lib/compression.js

188

index.js

@@ -6,129 +6,85 @@ //--------------------------------------------------------

const fsExtra = require('fs-extra');
const gracefulFs = require('graceful-fs');
const yaml = require('js-yaml');
const junk = require('junk');
const klaw = require('klaw-sync');
const minimatch = require('minimatch');
const ow = require('ow');
const path = require('path');
const fsExtra = require('fs-extra');
const gracefulFs = require('graceful-fs');
const compression = require('./lib/compression');
const json = require('./lib/json');
const misc = require('./lib/misc');
const xml = require('./lib/xml');
const yaml = require('./lib/yaml');
module.exports = {
class Fss {
access: gracefulFs.accessSync,
appendFile: gracefulFs.appendFileSync,
chmod: gracefulFs.chmodSync,
chown: gracefulFs.chownSync,
close: gracefulFs.closeSync,
copyFile: gracefulFs.copyFileSync,
exists: gracefulFs.existsSync,
fchmod: gracefulFs.fchmodSync,
fchown: gracefulFs.fchownSync,
fdatasync: gracefulFs.fdatasyncSync,
fstat: gracefulFs.fstatSync,
fsync: gracefulFs.fsyncSync,
ftruncate: gracefulFs.ftruncateSync,
futimes: gracefulFs.futimesSync,
lchmod: gracefulFs.lchmodSync,
lchown: gracefulFs.lchownSync,
link: gracefulFs.linkSync,
lstat: gracefulFs.lstatSync,
mkdir: gracefulFs.mkdirSync,
mkdtemp: gracefulFs.mkdtempSync,
open: gracefulFs.openSync,
readdir: gracefulFs.readdirSync,
readFile: gracefulFs.readFileSync,
readlink: gracefulFs.readlinkSync,
read: gracefulFs.readSync,
realpath: gracefulFs.realpathSync,
rename: gracefulFs.renameSync,
rmdir: gracefulFs.rmdirSync,
stat: gracefulFs.statSync,
symlink: gracefulFs.symlinkSync,
truncate: gracefulFs.truncateSync,
unlink: gracefulFs.unlinkSync,
utimes: gracefulFs.utimesSync,
writeFile: gracefulFs.writeFileSync,
write: gracefulFs.writeSync,
get access() { return gracefulFs.accessSync; }
get appendFile() { return gracefulFs.appendFileSync; }
get chmod() { return gracefulFs.chmodSync; }
get chown() { return gracefulFs.chownSync; }
get close() { return gracefulFs.closeSync; }
get copyFile() { return gracefulFs.copyFileSync; }
get exists() { return gracefulFs.existsSync; }
get fchmod() { return gracefulFs.fchmodSync; }
get fchown() { return gracefulFs.fchownSync; }
get fdatasync() { return gracefulFs.fdatasyncSync; }
get fstat() { return gracefulFs.fstatSync; }
get fsync() { return gracefulFs.fsyncSync; }
get ftruncate() { return gracefulFs.ftruncateSync; }
get futimes() { return gracefulFs.futimesSync; }
get lchmod() { return gracefulFs.lchmodSync; }
get lchown() { return gracefulFs.lchownSync; }
get link() { return gracefulFs.linkSync; }
get lstat() { return gracefulFs.lstatSync; }
get mkdir() { return gracefulFs.mkdirSync; }
get mkdtemp() { return gracefulFs.mkdtempSync; }
get open() { return gracefulFs.openSync; }
get readdir() { return gracefulFs.readdirSync; }
get readFile() { return gracefulFs.readFileSync; }
get readlink() { return gracefulFs.readlinkSync; }
get read() { return gracefulFs.readSync; }
get realpath() { return gracefulFs.realpathSync; }
get rename() { return gracefulFs.renameSync; }
get rmdir() { return gracefulFs.rmdirSync; }
get stat() { return gracefulFs.statSync; }
get symlink() { return gracefulFs.symlinkSync; }
get truncate() { return gracefulFs.truncateSync; }
get unlink() { return gracefulFs.unlinkSync; }
get utimes() { return gracefulFs.utimesSync; }
get writeFile() { return gracefulFs.writeFileSync; }
get write() { return gracefulFs.writeSync; }
copy: fsExtra.copySync,
emptyDir: fsExtra.emptyDirSync,
ensureFile: fsExtra.ensureFileSync,
ensureDir: fsExtra.ensureDirSync,
ensureLink: fsExtra.ensureLinkSync,
ensureSymlink: fsExtra.ensureSymlinkSync,
mkdirp: fsExtra.mkdirpSync,
mkdirs: fsExtra.mkdirsSync,
move: fsExtra.moveSync,
outputFile: fsExtra.outputFileSync,
outputJson: fsExtra.outputJsonSync,
pathExists: fsExtra.pathExistsSync,
readJson: fsExtra.readJsonSync,
remove: fsExtra.removeSync,
writeJson: fsExtra.writeJsonSync,
get copy() { return fsExtra.copySync; }
get emptyDir() { return fsExtra.emptyDirSync; }
get ensureFile() { return fsExtra.ensureFileSync; }
get ensureDir() { return fsExtra.ensureDirSync; }
get ensureLink() { return fsExtra.ensureLinkSync; }
get ensureSymlink() { return fsExtra.ensureSymlinkSync; }
get mkdirp() { return fsExtra.mkdirpSync; }
get mkdirs() { return fsExtra.mkdirsSync; }
get move() { return fsExtra.moveSync; }
get outputFile() { return fsExtra.outputFileSync; }
get pathExists() { return fsExtra.pathExistsSync; }
get remove() { return fsExtra.removeSync; }
get readCompressed() { return compression.read; }
get writeCompressed() { return compression.write; }
get outputCompressed() { return compression.output; }
get compressFile() { return compression.compress; }
get decompressFile() { return compression.decompress; }
//-- YAML
readYaml: (file) => {
ow(file, ow.string.label('file').nonEmpty);
get readJson() { return json.read; }
get writeJson() { return json.write; }
get outputJson() { return json.output; }
return yaml.safeLoad(gracefulFs.readFileSync(file, 'utf8'));
},
get readXml() { return xml.read; }
get writeXml() { return xml.write; }
get outputXml() { return xml.output; }
get readYaml() { return yaml.read; }
get writeYaml() { return yaml.write; }
get outputYaml() { return yaml.output; }
writeYaml: (file, object) => {
ow(file, ow.string.label('file').nonEmpty);
ow(object, ow.object.label('object'));
get scandir() { return misc.scandir; }
gracefulFs.writeFileSync(file, yaml.safeDump(object));
},
}
outputYaml: (file, object) => {
ow(file, ow.string.label('file').nonEmpty);
ow(object, ow.object.label('object'));
const dir = path.dirname(file);
if (!gracefulFs.existsSync(dir)) {
fsExtra.mkdirsSync(dir);
}
gracefulFs.writeFileSync(file, yaml.safeDump(object));
},
//-- scandir
scandir: (root, type, { recursive = false, fullPath = false, pattern = '**', keepJunk = false } = {}) => {
ow(root, ow.string.label('root').nonEmpty);
ow(type, ow.string.label('type').nonEmpty.is(() => { return ['file', 'dir'].includes(type) || `Must be 'file' or 'dir'`; }));
ow(recursive, ow.boolean.label('recursive'));
ow(fullPath, ow.boolean.label('fullPath'));
ow(pattern, ow.string.label('pattern').nonEmpty);
ow(keepJunk, ow.boolean.label('keepJunk'));
// Remove trailing slash
const rootPath = root.replace(/(.*)(\/)$/, '$1');
return klaw(rootPath, {
nodir: false,
nofile: type === 'dir',
depthLimit: recursive ? -1 : type === 'file' ? 0 : 1
})
.filter(({ path:curr, stats }) => {
const file = curr.split(path.sep).pop();
const relative = curr.substring(rootPath.length + 1);
return (
(type === 'dir' || (type === 'file' && !stats.isDirectory())) &&
(keepJunk || (!keepJunk && junk.not(file) && !['.gitkeep'].includes(file))) &&
minimatch(relative, pattern, { dot:true, matchBase:true })
);
})
.map((item) => {
return fullPath ? item.path : item.path.substring(rootPath.length + 1);
})
;
}
};
module.exports = new Fss();
{
"name": "@absolunet/fss",
"version": "1.2.0",
"description": "graceful-fs / fs-extra sync wrapper",
"version": "1.3.0",
"description": "graceful-fs / fs-extra sync wrapper with goodies",
"definition": "",

@@ -15,4 +15,7 @@ "homepage": "https://github.com/absolunet/node-fss",

"graceful-fs",
"gunzip",
"gzip",
"klaw",
"sync",
"xml",
"yaml"

@@ -29,3 +32,3 @@ ],

"engines": {
"node": ">= 10.9.0"
"node": ">= 10.10.0"
},

@@ -44,6 +47,8 @@ "main": "index.js",

"junk": "^2.1.0",
"klaw-sync": "^4.0.0",
"klaw-sync": "^5.0.0",
"minimatch": "^3.0.4",
"ow": "^0.6.0"
"ow": "^0.6.0",
"xml2js": "^0.4.19",
"xml2js-parser": "^1.1.1"
}
}

@@ -9,3 +9,3 @@ # @absolunet/fss

> graceful-fs / fs-extra sync wrapper
> graceful-fs / fs-extra sync wrapper with goodies

@@ -36,99 +36,249 @@

<!-- access -->
### access
Maps [`fs.accessSync`](https://nodejs.org/api/fs.html#fs_fs_accesssync_path_mode)
<!-- appendFile -->
### appendFile
Maps [`fs.appendFileSync`](https://nodejs.org/api/fs.html#fs_fs_appendfilesync_path_data_options)
<!-- chmod -->
### chmod
Maps [`fs.chmodSync`](https://nodejs.org/api/fs.html#fs_fs_chmodsync_path_mode)
<!-- chown -->
### chown
Maps [`fs.chownSync`](https://nodejs.org/api/fs.html#fs_fs_chownsync_path_uid_gid)
<!-- close -->
### close
Maps [`fs.closeSync`](https://nodejs.org/api/fs.html#fs_fs_closesync_fd)
<!-- compressFile -->
### compressFile(source *[, destination]*)
Compresses file using gzip
Return `String` destination
#### source
*Required*<br>
Type: `String`<br>
Path of file to compress.
#### destination
Type: `String`<br>
Default: Same as source with a `.gz` added at the end<br>
Path of file when compressed.
<!-- copy -->
### copy
Maps [`fse.copySync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/copy-sync.md)
<!-- copyFile -->
### copyFile
Maps [`fs.copyFileSync`](https://nodejs.org/api/fs.html#fs_fs_copyfilesync_src_dest_flags)
<!-- decompressFile -->
### decompressFile(source *[, destination]*)
Decompresses file using gzip
Return `String` destination
#### source
*Required*<br>
Type: `String`<br>
Path of file to decompress.
#### destination
Type: `String`<br>
Default: Same as source with the `.gz` removed at the end<br>
Path of file when decompressed.
<!-- emptyDir -->
### emptyDir
Maps [`fse.emptyDirSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/emptyDir-sync.md)
### ensureFile
Maps [`fse.ensureFileSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureFile-sync.md)
<!-- ensureDir -->
### ensureDir
Maps [`fse.ensureDirSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureDir-sync.md)
<!-- ensureFile -->
### ensureFile
Maps [`fse.ensureFileSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureFile-sync.md)
<!-- ensureLink -->
### ensureLink
Maps [`fse.ensureLinkSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureLink-sync.md)
<!-- ensureSymlink -->
### ensureSymlink
Maps [`fse.ensureSymlinkSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureSymlink-sync.md)
<!-- exists -->
### exists
Maps [`fs.existsSync`](https://nodejs.org/api/fs.html#fs_fs_existssync_path)
<!-- fchmod -->
### fchmod
Maps [`fs.fchmodSync`](https://nodejs.org/api/fs.html#fs_fs_fchmodsync_fd_mode)
<!-- fchown -->
### fchown
Maps [`fs.fchownSync`](https://nodejs.org/api/fs.html#fs_fs_fchownsync_fd_uid_gid)
<!-- fdatasync -->
### fdatasync
Maps [`fs.fdatasyncSync`](https://nodejs.org/api/fs.html#fs_fs_fdatasyncsync_fd)
<!-- fstat -->
### fstat
Maps [`fs.fstatSync`](https://nodejs.org/api/fs.html#fs_fs_fstatsync_fd_options)
<!-- fsync -->
### fsync
Maps [`fs.fsyncSync`](https://nodejs.org/api/fs.html#fs_fs_fsyncsync_fd)
<!-- ftruncate -->
### ftruncate
Maps [`fs.ftruncateSync`](https://nodejs.org/api/fs.html#fs_fs_ftruncatesync_fd_len)
<!-- futimes -->
### futimes
Maps [`fs.futimesSync`](https://nodejs.org/api/fs.html#fs_fs_futimessync_fd_atime_mtime)
<!-- lchmod -->
### lchmod
Maps [`fs.lchmodSync`](https://nodejs.org/api/fs.html#fs_fs_lchmodsync_path_mode)
<!-- lchown -->
### lchown
Maps [`fs.lchownSync`](https://nodejs.org/api/fs.html#fs_fs_lchownsync_path_uid_gid)
<!-- link -->
### link
Maps [`fs.linkSync`](https://nodejs.org/api/fs.html#fs_fs_linksync_existingpath_newpath)
<!-- lstat -->
### lstat
Maps [`fs.lstatSync`](https://nodejs.org/api/fs.html#fs_fs_lstatsync_path_options)
<!-- mkdir -->
### mkdir
Maps [`fs.mkdirSync`](https://nodejs.org/api/fs.html#fs_fs_mkdirsync_path_mode)
<!-- mkdirp -->
### mkdirp
Maps [`fse.mkdirpSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureDir-sync.md)
<!-- mkdirs -->
### mkdirs
Maps [`fse.mkdirsSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/ensureDir-sync.md)
<!-- mkdtemp -->
### mkdtemp
Maps [`fs.mkdtempSync`](https://nodejs.org/api/fs.html#fs_fs_mkdtempsync_prefix_options)
<!-- move -->
### move
Maps [`fse.moveSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/move-sync.md)
<!-- open -->
### open
Maps [`fs.openSync`](https://nodejs.org/api/fs.html#fs_fs_opensync_path_flags_mode)
<!-- outputCompressed -->
### outputCompressed(file, content)
Almost the same as writeCompressed, except that if the directory does not exist, it's created.
#### file
*Required*<br>
Type: `String`<br>
Path of file to write.
#### content
*Required*<br>
Type: `String`<br>
Content to write.
<!-- outputFile -->
### outputFile
Maps [`fse.outputFileSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/outputFile-sync.md)
### outputJson
Maps [`fse.outputJsonSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/outputJson-sync.md)
<!-- outputJson -->
### outputJson(file, object *[, options]*)
Almost the same as writeJson, except that if the directory does not exist, it's created.
#### file
*Required*<br>
Type: `String`<br>
Path of file to write. (If it ends with `.gz` it will be compressed using gzip)
#### object
*Required*<br>
Type: `Object`<br>
Object to write.
#### options.replacer
Type: `Function`<br>
JSON.stringify [replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Syntax).
#### options.space
Type: `String` or `Number`<br>
JSON.stringify [space](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Syntax).
<!-- outputXml -->
### outputXml(file, object *[, options]*)
Almost the same as writeXml, except that if the directory does not exist, it's created.
#### file
*Required*<br>
Type: `String`<br>
Path of file to write. (If it ends with `.gz` it will be compressed using gzip)
#### object
*Required*<br>
Type: `Object`<br>
Object to write.
#### options
Type: `Object`<br>
xml2js.Builder().buildObject [options](https://github.com/Leonidas-from-XIV/node-xml2js#options-for-the-builder-class).
<!-- outputYaml -->
### outputYaml(file, object)

@@ -140,3 +290,3 @@ Almost the same as writeYaml, except that if the directory does not exist, it's created.

Type: `String`<br>
Path of file to write.
Path of file to write. (If it ends with `.gz` it will be compressed using gzip)

@@ -148,25 +298,70 @@ #### object

<br>
<!-- pathExists -->
### pathExists
Maps [`fse.pathExistsSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/pathExists-sync.md)
<!-- read -->
### read
Maps [`fs.readSync`](https://nodejs.org/api/fs.html#fs_fs_readsync_fd_buffer_offset_length_position)
<!-- readCompressed -->
### readCompressed(file)
Reads and decompresses file using gzip.<br>
Return `String`
#### file
*Required*<br>
Type: `String`<br>
Path of file to read.
<!-- readdir -->
### readdir
Maps [`fs.readdirSync`](https://nodejs.org/api/fs.html#fs_fs_readdirsync_path_options)
<!-- readFile -->
### readFile
Maps [`fs.readFileSync`](https://nodejs.org/api/fs.html#fs_fs_readfilesync_path_options)
<!-- readJson -->
### readJson(file *[, reviver]*)
Reads a JSON file and then parses it into an object.<br>
Return `Object`
#### file
*Required*<br>
Type: `String`<br>
Path of file to read. (If it ends with `.gz` it will be decompressed using gzip)
#### reviver
Type: `Function`<br>
JSON.parse [reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Syntax).
<!-- readlink -->
### readlink
Maps [`fs.readlinkSync`](https://nodejs.org/api/fs.html#fs_fs_readlinksync_path_options)
### read
Maps [`fs.readSync`](https://nodejs.org/api/fs.html#fs_fs_readsync_fd_buffer_offset_length_position)
### readJson
Maps [`fse.readJsonSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/readJson-sync.md)
<!-- readXml -->
### readXml(file *[, options]*)
Reads a XML file and then parses it into an object.<br>
Return `Object`
#### file
*Required*<br>
Type: `String`<br>
Path of file to read. (If it ends with `.gz` it will be decompressed using gzip)
#### options
Type: `Object`<br>
xml2jsParser.parseStringSync [options](https://github.com/vavere/xml2js-parser#options).
<!-- readYaml -->
### readYaml(file)

@@ -179,20 +374,25 @@ Reads a YAML file and then parses it into an object.<br>

Type: `String`<br>
Path of file to read.
Path of file to read. (If it ends with `.gz` it will be decompressed using gzip)
<br>
<!-- realpath -->
### realpath
Maps [`fs.realpathSync`](https://nodejs.org/api/fs.html#fs_fs_realpathsync_path_options)
<!-- realpath.native -->
### realpath.native
Maps [`fs.realpathSync.native`](https://nodejs.org/api/fs.html#fs_fs_realpathsync_native_path_options)
### rename
Maps [`fs.renameSync`](https://nodejs.org/api/fs.html#fs_fs_renamesync_oldpath_newpath)
<!-- remove -->
### remove
Maps [`fse.removeSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/remove-sync.md)
<!-- rename -->
### rename
Maps [`fs.renameSync`](https://nodejs.org/api/fs.html#fs_fs_renamesync_oldpath_newpath)
<!-- rmdir -->
### rmdir

@@ -202,2 +402,3 @@ Maps [`fs.rmdirSync`](https://nodejs.org/api/fs.html#fs_fs_rmdirsync_path)

<!-- scandir -->
### scandir(root, type, [options])

@@ -237,31 +438,96 @@ Uses [klaw-sync](https://github.com/manidlou/node-klaw-sync) to scan directory for files or directories.<br>

<br>
<!-- stat -->
### stat
Maps [`fs.statSync`](https://nodejs.org/api/fs.html#fs_fs_statsync_path_options)
<!-- symlink -->
### symlink
Maps [`fs.symlinkSync`](https://nodejs.org/api/fs.html#fs_fs_symlinksync_target_path_type)
<!-- truncate -->
### truncate
Maps [`fs.truncateSync`](https://nodejs.org/api/fs.html#fs_fs_truncatesync_path_len)
<!-- unlink -->
### unlink
Maps [`fs.unlinkSync`](https://nodejs.org/api/fs.html#fs_fs_unlinksync_path)
<!-- utimes -->
### utimes
Maps [`fs.utimesSync`](https://nodejs.org/api/fs.html#fs_fs_utimessync_path_atime_mtime)
### writeFile
Maps [`fs.writeFileSync`](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options)
<!-- write -->
### write
Maps [`fs.writeSync`](https://nodejs.org/api/fs.html#fs_fs_writesync_fd_buffer_offset_length_position)
### writeJson
Maps [`fse.writeJsonSync`](https://github.com/jprichardson/node-fs-extra/blob/master/docs/writeJson-sync.md)
<!-- writeCompressed -->
### writeCompressed(file, content)
Compresses and writes content to file using gzip.
#### file
*Required*<br>
Type: `String`<br>
Path of file to write.
#### content
*Required*<br>
Type: `String`<br>
Content to write.
<!-- writeFile -->
### writeFile
Maps [`fs.writeFileSync`](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options)
<!-- writeJson -->
### writeJson(file, content *[, options]*)
Writes an object to a JSON file.
#### file
*Required*<br>
Type: `String`<br>
Path of file to write. (If it ends with `.gz` it will be compressed using gzip)
#### object
*Required*<br>
Type: `Object`<br>
Object to write.
#### options.replacer
Type: `Function`<br>
JSON.stringify [replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Syntax).
#### options.space
Type: `String` or `Number`<br>
JSON.stringify [space](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Syntax).
<!-- writeXml -->
### writeXml(file, content *[, options]*)
Writes an object to a XML file.
#### file
*Required*<br>
Type: `String`<br>
Path of file to write. (If it ends with `.gz` it will be compressed using gzip)
#### object
*Required*<br>
Type: `Object`<br>
Object to write.
#### options
Type: `Object`<br>
xml2js.Builder().buildObject [options](https://github.com/Leonidas-from-XIV/node-xml2js#options-for-the-builder-class).
<!-- writeYaml -->
### writeYaml(file, object)

@@ -273,3 +539,3 @@ Writes an object to a YAML file.

Type: `String`<br>
Path of file to write.
Path of file to write. (If it ends with `.gz` it will be compressed using gzip)

@@ -281,8 +547,6 @@ #### object

<br>
## License
MIT © [Absolunet](https://absolunet.com)
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