Socket
Socket
Sign inDemoInstall

files-repo

Package Overview
Dependencies
8
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 1.3.0

19

index.js

@@ -34,3 +34,3 @@ "use strict";

if ( config.RemoveOlderFiles ) {
this.removeOlder = RemoveOlder(this. config.RemoveOlderFiles);
this.removeOlder = RemoveOlder(this, config.RemoveOlderFiles);
this.removeOlder.StartCronToRemoveOlderFiles();

@@ -230,4 +230,21 @@ }

}
async ConcatGroupOfFiles( filesToGroup, extension ) {
let manifestNewFile = await this.AllocateNewFileLocation( extension );
for( let fileIdToAdd of filesToGroup ) {
await this.AppendTo( fileIdToAdd, manifestNewFile.fileId );
}
return manifestNewFile.fileId;
}
async AppendTo( fileIdOrigin, fileIdDestination ) {
let fileIdOriginManifest = await this.GetFileManifest( fileIdOrigin );
let fileDestination = await this.GetFileManifest( fileIdDestination );
await Utils.appendFile( fileIdOriginManifest.location, fileDestination.location );
}
}
module.exports = (config) => new FilesManager(config);

8

lib/removeolder.js

@@ -5,3 +5,3 @@ "use strict";

const CRONJOBCONFIGURATION = "0 */1 * * * *"; // Every minute
const CRONJOBCONFIGURATION = "*/5 * * * * *"; // Every minute

@@ -49,6 +49,6 @@ let instance;

instance.filesToRemove = [];
await this.filesManager.IterateAll( this.checkFile );
await instance.filesManager.IterateAll( instance.checkFile );
for( let fileIdToRemove of this.filesToRemove ) {
await this.filesManager.DeleteFile( fileIdToRemove );
for( let fileIdToRemove of instance.filesToRemove ) {
await instance.filesManager.DeleteFile( fileIdToRemove );
}

@@ -55,0 +55,0 @@

@@ -112,2 +112,23 @@ "use strict";

appendFile: function( filePathToAppend, detinationFilePath ) {
return new Promise( (resolve,reject) => {
this.readFile(filePathToAppend)
.then( (data) => {
fs.open(detinationFilePath, 'a', (err, fd) => {
if (err) reject(err);
else {
fs.appendFile(fd, data, (err) => {
fs.close(fd, (err) => {
if (err) reject(err);
else resolve();
});
if (err) reject(err);
});
}
});
})
.catch( (err) => reject(err) );
});
},
ensureDir: async function( path ) {

@@ -114,0 +135,0 @@ return fsExtra.ensureDir(path);

{
"name": "files-repo",
"version": "1.2.0",
"version": "1.3.0",
"description": "Files manager module for easy files managemente in a NodeJS project",

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

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

before( async () => {
await FsExtra.ensureDir( PATH_TO_FILES_REPOSITORY );
await FsExtra.remove(PATH_TO_FILES_REPOSITORY);
await FsExtra.ensureDir(PATH_TO_FILES_REPOSITORY);
});

@@ -26,2 +27,3 @@

Assert.isString( fileId );
Assert.equal( fileId.length, 32 );

@@ -183,2 +185,30 @@ });

});
it( '# Concat with two files', async() => {
let fileId1 = await f.AddFromBuffer( Buffer.from("a") );
let fileId2 = await f.AddFromBuffer( Buffer.from("b") );
let filesToConcat = [fileId1, fileId2];
let fileIdConcated = await f.ConcatGroupOfFiles(filesToConcat, "txt");
Assert.equal( fileIdConcated.length, 32 );
Assert.isString( fileIdConcated );
});
it( '# Concat with two files and read file', async() => {
let fileId1 = await f.AddFromBuffer( Buffer.from("a") );
let fileId2 = await f.AddFromBuffer( Buffer.from("b") );
let filesToConcat = [fileId1, fileId2];
let fileIdConcated = await f.ConcatGroupOfFiles(filesToConcat, "txt");
Assert.equal( fileIdConcated.length, 32 );
Assert.isString( fileIdConcated );
let content = await f.ReadFile( fileIdConcated );
Assert.equal( content, "ab" );
});
});

@@ -6,2 +6,3 @@ "use strict";

const RemoveOlder = require("../lib/removeolder");
const FsExtra = require("fs-extra");

@@ -20,3 +21,8 @@ const Files = require("..");

describe( '@gomezbl/removeolder tests', () => {
it( "ShouldBeRemoved with older date", () => {
before( async () => {
await FsExtra.remove(PATH_TO_FILES_REPOSITORY);
await FsExtra.ensureDir(PATH_TO_FILES_REPOSITORY);
});
it( "ShouldBeRemoved with older date", () => {
let oldDate = new Date( new Date().getTime() - 10*60000 );

@@ -23,0 +29,0 @@ Assert.isTrue( removeOlder.ShouldBeRemoved( oldDate ) );

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc