Global variable alert! #2

Closed
opened 2011-04-10 06:03:35 -07:00 by jakobmattsson · 1 comment
jakobmattsson commented 2011-04-10 06:03:35 -07:00 (Migrated from github.com)

Hi,

Nice functions, saved me the trouble of writing them myself. On the other hand, I found some issues and would like to make you aware of them. The following lines are not doing what you think (or you might just have done some naughty copy-pasting):

var contents = fs.readFileSync(sourceDir + "/" + files[i], encoding="utf8");
fs.writeFileSync(newDirLocation + "/" + files[i], contents, encoding="utf8");

The last parameter in both lines are an expression that creates a global variable called "encoding", sets it to "utf8" and then passes the value of "encoding" to the function. Remove "encoding=" and just use "utf8" as a parameter instead.

By the way, setting the encoding to utf8 doesn't really work well with binary files, like images. I would just skip the encoding parameter altogether.

Cheers!

Hi, Nice functions, saved me the trouble of writing them myself. On the other hand, I found some issues and would like to make you aware of them. The following lines are not doing what you think (or you might just have done some naughty copy-pasting): ``` var contents = fs.readFileSync(sourceDir + "/" + files[i], encoding="utf8"); fs.writeFileSync(newDirLocation + "/" + files[i], contents, encoding="utf8"); ``` The last parameter in both lines are an expression that creates a global variable called "encoding", sets it to "utf8" and then passes the value of "encoding" to the function. Remove "encoding=" and just use "utf8" as a parameter instead. By the way, setting the encoding to utf8 doesn't really work well with binary files, like images. I would just skip the encoding parameter altogether. Cheers!
ryanmcgrath commented 2011-04-10 09:28:40 -07:00 (Migrated from github.com)

Hey,

Thanks for pointing this out! I had been meaning to circle around and fix it for months; this was abstracted out of a personal project many moons ago, and as such definitely had one or two warts since I kind of just threw it out there for people to use.

Resolved in 445a283. Thanks!

  • Ryan
Hey, Thanks for pointing this out! I had been meaning to circle around and fix it for months; this was abstracted out of a personal project many moons ago, and as such definitely had one or two warts since I kind of just threw it out there for people to use. Resolved in 445a283. Thanks! - Ryan
This repository is archived. You cannot comment on issues.
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: code/wrench-js#2
No description provided.