Closed terryupton closed 7 years ago
+1
+1
OS : Windows 10 Node: v7.1.0 npm: 3.10.9
Hello
I have this problem as well
crypto.js:74
this._handle.update(data, encoding);
^
TypeError: Data must be a string or a buffer
at TypeError (native)
at Hash.update (crypto.js:74:16)
Here's my environment :
OS : MacOS Sierra Node : v6.9.2 Npm : 3.10.9
Any ideas about this?
The issue is coming from index.js:151
:
var batchDir = crypto.createHash ('md5').update(Date.now()).digest ('base64'),
If you tack a .toString()
onto the Date.now()
call (to make sure it's a string, as the error states), the script still dies a little further down. I'll update again if I get it working
I can create a PR to fix the issue, but the code I'm getting from NPM (v1.0.8) does not match the code in this repo (v1.0.3).
I've never seen this before, so I'm not really sure where the newer 1.0.8 code is being pulled from?
Last few updates to the npm were 2 months ago and the code from the repo is more like 10+ months old
I have the same issue.
There's some news to fix it ?
+1
+1
+1
+1
+1 Is this project still alive?
+1
+1
⚰️
same issue
The main problems are the way the directory and files are being named. When using a base64 encoding in the digest function, you risk having a '/' in the folder or file name. I've added the updated batchOptimize function using hex encoding.
/**
* Batch optimize files and push.
*
* @param {Array} files - Array of files to batch optimize
* @param {Object} options - Options. Currently status is supported as boolean indicating whether to display optmization result status or not
* @param {Function} next - The callback to continue processing
*/
var batchOptimize = function (files, options, next) {
if (files.length === 0)
next (files)
var batchDir = crypto.createHash ('md5').update (Date.now().toString()).digest ('hex'),
jpegminiEnabled = options.jpegmini ? '--jpegmini' : '',
scriptParams = path.normalize (batchDir) + ' ' + jpegminiEnabled
// Make batch directory
fs.mkdirSync (batchDir)
// Add files to optimize to batch directory
for (var i = 0, length = files.length; i < length; i++) {
var file = files[i]
file.batchFilePath = path.join (batchDir, crypto.createHash ('md5').update (file.path).digest ('hex') + path.extname (file.path))
fs.writeFileSync (file.batchFilePath, file.contents)
}
// Optimize files
exec ('bash node_modules/gulp-imageoptim/scripts/optimize.bash ' + scriptParams, function (error, stdout) {
var result = {}
if (error === null) {
var savings = parseInt (stdout.replace (/.*\(([0-9]+)(\.[0-9]+)?\%\)/, '$1')),
msg = ''
if (savings > 0) {
// Copy optimized file contents to original and remove file
for (var i = 0, length = files.length; i < length; i++) {
var file = files[i]
file.contents = new Buffer(fs.readFileSync (file.batchFilePath))
stdout = stdout.replace (file.batchFilePath, path.basename (file.path))
}
msg = stdout.replace ('TOTAL was', 'Filesize total was')
} else {
msg = 'Saving: 0%\n'
}
result = {
'files' : files.length,
'msg' : msg,
'savings' : savings,
'type' : 'success'
}
} else {
console.error (error)
}
// Delete batch directory
removeDirectory (batchDir)
// Display optmization result status?
if (options.status) {
displayOptimizationResults (result)
}
next (files)
})
}
For some reason this repo and the version coming from npm are not the same. Could you please explain why, @allbitsnbytes? I'd would have gladly provided a pull request.
someone needs to push to NPM and I'm guessing allbitnbytes has permissions. Might be time to fork and push a new version to NPM
He must not use github anymore but kept updating the npm? I would take it over but I'm not sure how okay he is with it. I'll look for some sort of other contact information
@HarrisJT His Twitter account seems to be still alive... https://twitter.com/allbitsnbytes
Guys sorry for not getting to this earlier. I didn't get the github notifications about this thread. I've published the fix to NPM in version 1.0.9. I'll update the this repo later.
@ginlime thank you for alerting me on twitter.
@patrickmatsumura and @tariq86 thank you for looking into this issue.
I have setup to use imageOptim in my gulp project. Each time I run this I am getting the following errors;
Any ideas on what is causing this or how to resolve it?