Socket
Socket
Sign inDemoInstall

file-utils

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-utils - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

6

lib/env.js
var path = require('path');
var util = require('util');
var _ = require('lodash');
var isBinaryFile = require('isbinaryfile');
var File = require('./file');

@@ -36,5 +37,8 @@

this.write = function(filepath, contents, options) {
if (!isBinaryFile(path.resolve(filepath))) {
contents = String(contents);
}
return this.applyWriteFilters({
path: filepath,
contents: String(contents)
contents: contents
}, this.applyValidationFilters, options);

@@ -41,0 +45,0 @@ };

5

package.json
{
"name": "file-utils",
"version": "0.1.3",
"version": "0.1.4",
"description": "Sync file utility for Node.js command line tools",

@@ -19,3 +19,4 @@ "main": "index.js",

"minimatch": "~0.2.12",
"findup-sync": "~0.1.2"
"findup-sync": "~0.1.2",
"isbinaryfile": "~0.1.9"
},

@@ -22,0 +23,0 @@ "devDependencies": {

@@ -113,3 +113,3 @@ file-utils [![](https://travis-ci.org/SBoudrias/file-utils.png)](https://travis-ci.org/SBoudrias/file-utils)

The filter function take a file object as parameter. This file object is a hash containing a `path` and a `contents` property.
The filter function take a file object as parameter. This file object is a hash containing a `path` (String) and a `contents` (String if text file, Buffer otherwise) property.

@@ -116,0 +116,0 @@ Return `true` to allow the file to be written. Return `false` or an error message `String` to disallow the write action.

@@ -223,2 +223,22 @@ 'use strict';

},
'validation with text file': function(test) {
test.expect(1);
this.env.registerValidationFilter('tmp', function(file) {
test.ok(typeof file.contents === 'string');
test.done();
return 'abort';
});
var textPath = path.join(__dirname, 'fixtures/utf8.txt');
this.env.copy(textPath, textPath);
},
'validation with binary file': function(test) {
test.expect(1);
this.env.registerValidationFilter('tmp', function(file) {
test.ok(file.contents instanceof Buffer);
test.done();
return 'abort';
});
var binaryPath = path.join(__dirname, 'fixtures/octocat.png');
this.env.copy(binaryPath, binaryPath);
},
'failing validation and custom error message': function(test) {

@@ -225,0 +245,0 @@ test.expect(2);

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