Skip to content
Browse files

More Crux File operations. Fixed bug in Url.path. Server supports req…

…uire option
  • Loading branch information...
1 parent f705d40 commit 2174e77380dbd1c73bae0e6621fc7f551b6e8158 @richcollins richcollins committed
Showing with 39 additions and 5 deletions.
  1. +34 −4 lib/NodeCrux/File.js
  2. +1 −1 lib/NodeCrux/Url.js
  3. +4 −0 server.js
View
38 lib/NodeCrux/File.js
@@ -8,16 +8,36 @@ File = Proto.clone().newSlots({
isOpen: false,
encoding: "utf8"
}).setSlots({
- open: function()
+ open: function(flags)
+ {
+ return this.openForReading();
+ },
+
+ openWithFlags: function(flags)
{
if(!this.isOpen())
{
- this.setFd(fs.openSync(this.path()));
+ this.setFd(fs.openSync(this.path(), flags));
}
return this;
},
+ openForReading: function()
+ {
+ return this.openWithFlags("r");
+ },
+
+ openForWriting: function()
+ {
+ return this.openWithFlags("w");
+ },
+
+ openForAppending: function()
+ {
+ return this.openWithFlags("a");
+ },
+
close: function()
{
fs.closeSync(this.fd());
@@ -25,6 +45,16 @@ File = Proto.clone().newSlots({
return this;
},
+ write: function(str)
+ {
+ fs.writeSync(this.fd(), str, null, this.encoding());
+ },
+
+ writeln: function()
+ {
+ this.write(Arguments_asArray(arguments).join("") + "\n");
+ },
+
exists: function()
{
try
@@ -51,11 +81,11 @@ File = Proto.clone().newSlots({
{
if(this.isOpen())
{
- this.close().open();
+ throw new Error("createIfAbsent before opening open file");
}
else
{
- this.open().close();
+ this.openForWriting().close();
}
}
return this;
View
2 lib/NodeCrux/Url.js
@@ -16,7 +16,7 @@ Url = Proto.clone().newSlots({
this.setHost(parts.hostname);
this.setPort(parts.port);
- this.setPath("" + parts.pathname);
+ this.setPath("" + (parts.pathname || ""));
this.setResource(this.path() + (parts.search || ""));
this.setQueryParams(parts.query || {});
View
4 server.js
@@ -56,6 +56,10 @@ while (option = args.shift())
pidFile.remove();
});
}
+ else if(option == "-require")
+ {
+ require(args.shift());
+ }
else
{
sys.puts("Unknown option '" + option + "'")

0 comments on commit 2174e77

Please sign in to comment.
Something went wrong with that request. Please try again.