file-utils
Advanced tools
Comparing version 0.1.3 to 0.1.4
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 @@ }; |
{ | ||
"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); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83669
1665
7
+ Addedisbinaryfile@~0.1.9
+ Addedisbinaryfile@0.1.9(transitive)