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

fs-merger

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-merger - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

8

dist/index.js

@@ -15,3 +15,4 @@ "use strict";

'readFileMeta',
'entries'
'entries',
'at'
]);

@@ -52,3 +53,4 @@ function getRootAndPrefix(node) {

}
if (!path.isAbsolute(relativePath)) {
// at is a spcfical property exist in FSMerge which takes number as input do not perform path operation on it.
if (propertyName == 'at' || !path.isAbsolute(relativePath)) {
// if property is present in the FSMerge do not hijack it with fs operations

@@ -82,3 +84,3 @@ if (this[propertyName]) {

get(target, propertyName) {
if (WHITELISTEDOPERATION.has(propertyName) || self[propertyName]) {
if (WHITELISTEDOPERATION.has(propertyName)) {
return handleOperation.bind(self, { target, propertyName });

@@ -85,0 +87,0 @@ }

{
"name": "fs-merger",
"version": "3.0.0",
"version": "3.0.1",
"description": "Reads files from a real location",

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

@@ -166,1 +166,84 @@ ## Introduction

This new library helped in removing two funnels which where used only for the sake of renaming at the output of persitent filter and mergeTree was performed because persitent filter was restricted to accept only one inputNode.
## FSMerger.fs
`FSMerge.fs` is a proxy for the file operations and few whitelisted fsmerger operations
Following are the operation which `FSMerger.fs` supports
All these are standard `fs` operations. Refer node guide for [file handling](https://nodejs.org/api/fs.html)
* readFileSync
* existsSync
* lstatSync
* statSync
* readdirSync
* readdir
Following are specfic to `FSMerger`
* readFileMeta
Reads the filemeta passed down while creating the new FSMerger instance for a specific root.
Ex:
```js
/*
fixture
|
-- docs
|
-- c.txt
-- d.txt
*/
let FSMergerObjectWithPrefix = {
root: 'fixture/docs',
prefix: 'documents'
}
let FSMerge = require('fs-merger');
let fsmerge = new FSMerge([FSMergerObjectWithPrefix]);
let filemeta = fsmerge.fs.readFileMeta('c.txt');
/*
filemeta will look something like this
{
path: 'fixture/docs/c.txt',
prefix: 'document'
getDestinationPath: undefined
}
*/
```
* at
This function is used to retrive file from a specfic input path (or root) directory. This function can used when we have same filename in mulitple inputPaths and we want spicific inputPath
ex:
```js
let FSMerge = require('fs-merger');
let fsmerge = new FSMerge(['test-1', 'test-2', 'test-3']);
/* test-1
|
-- a.txt
-- b.txt
test-2
|
-- c.txt
-- d.txt
-- sub-dir
|
-- x.txt
-- y.txt
test-3
|
-- e.txt
-- a.txt
*/
let contentA = fs.readFileSync('a.txt'); // content of test-3/a.txt; here we merge left to right, duplicate files are overwritten
let contentB = fsmerge.fs.at(0).readFileSync('a.txt'); // content of test-1/a.txt
let contentC = fsmerge.fs.at(2).readFileSync('a.txt'); // content of test-3/a.txt; here we merge left to right, duplicate files are overwritten
let contentSubDir = fsmerge.fs.at(1).readFileSync('sub-dir/x.txt'); //content of test-2/sub-dir/x.txt
```
* entries
`entries` performs same functionality as in `walk-sync`. Refer the `walk-sync` [guide here](https://github.com/joliss/node-walk-sync#entries).

@@ -30,3 +30,4 @@ "use strict";

'readFileMeta',
'entries'
'entries',
'at'
]);

@@ -70,3 +71,5 @@

}
if (!path.isAbsolute(relativePath)) {
// at is a spcfical property exist in FSMerge which takes number as input do not perform path operation on it.
if (propertyName == 'at' || !path.isAbsolute(relativePath)) {
// if property is present in the FSMerge do not hijack it with fs operations

@@ -106,3 +109,3 @@ if (this[propertyName]) {

get(target, propertyName: string) {
if(WHITELISTEDOPERATION.has(propertyName) || self[propertyName]) {
if(WHITELISTEDOPERATION.has(propertyName)) {
return handleOperation.bind(self, {target, propertyName})

@@ -109,0 +112,0 @@ } else {

@@ -241,4 +241,18 @@ "use strict";

fsMerger.fs.writeFileSync('read.md', 'test');
}).to.throw(`Operation writeFileSync is not allowed with FSMerger.fs. Allowed operations are readFileSync,existsSync,lstatSync,statSync,readdirSync,readdir,readFileMeta,entries`);
}).to.throw(`Operation writeFileSync is not allowed with FSMerger.fs. Allowed operations are readFileSync,existsSync,lstatSync,statSync,readdirSync,readdir,readFileMeta,entries,at`);
});
it('acessing FSMerger non whitelisted operation must throw error', function () {
let fsMerger = new FSMerge(['fixtures/test-1']);
expect(()=>{
fsMerger.fs._generateMap();
}).to.throw(`Operation _generateMap is not allowed with FSMerger.fs. Allowed operations are readFileSync,existsSync,lstatSync,statSync,readdirSync,readdir,readFileMeta,entries,at`);
});
it('acessing FSMerger non whitelisted properties must throw error', function () {
let fsMerger = new FSMerge(['fixtures/test-1']);
expect(()=>{
fsMerger.fs._dirList;
}).to.throw(`Operation _dirList is not allowed with FSMerger.fs. Allowed operations are readFileSync,existsSync,lstatSync,statSync,readdirSync,readdir,readFileMeta,entries,at`);
});
});

@@ -310,3 +324,8 @@

});
it('can access file contents using fs proxy', function() {
let indexMerger = fsMerger.fs.at(0);
let content = indexMerger.readFileSync('a.txt', 'utf-8');
expect(content).to.be.equal('hello');
});
});
});

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