From 16ef5029dee64e066505466f0d8223b18be6e883 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 5 Mar 2009 18:17:36 +0100 Subject: [PATCH] add blockingFileRead to tide me over until I can get a proper file interface. --- node.cc | 17 +++++++++++++++++ spec/index.html | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/node.cc b/node.cc index cd2fc66792..00ccc5f460 100644 --- a/node.cc +++ b/node.cc @@ -57,6 +57,8 @@ ReadFile (const string& name) return result; } + + static void ParseOptions (int argc, char* argv[], map& options, string* file) { @@ -121,6 +123,17 @@ LogCallback (const Arguments& args) return Undefined(); } +static Handle +BlockingFileReadCallback (const Arguments& args) +{ + if (args.Length() < 1) return v8::Undefined(); + HandleScope scope; + + String::Utf8Value filename(args[0]); + + return ReadFile (*filename); +} + static void OnFatalError (const char* location, const char* message) { @@ -153,6 +166,10 @@ main (int argc, char *argv[]) Local g = Context::GetCurrent()->Global(); g->Set( String::New("log"), FunctionTemplate::New(LogCallback)->GetFunction()); + g->Set( String::New("blockingFileRead") + , FunctionTemplate::New(BlockingFileReadCallback)->GetFunction() + ); + Init_timer(g); Init_tcp(g); Init_http(g); diff --git a/spec/index.html b/spec/index.html index b8819993d9..0b88b57112 100644 --- a/spec/index.html +++ b/spec/index.html @@ -3,6 +3,8 @@ Node API +
@@ -52,6 +54,8 @@
  • 3 TCP Client
  • 4 Timers +
  • 5 Blocking + Functions @@ -241,3 +245,26 @@ will be made. + +

    5 Blocking Functions

    + +

    Node includes a number of blocking functions in its API. Some of these + will be removed in the future as the software improves. + +

    +
    log(string)
    +
    +

    This function outputs the string to the stadard output device + (usually the console). + Its speed is dependent on where stdout is piped to. +

    + + +
    blockingFileRead(filename)
    +
    +

    This method opens a file from the file system and reads returns + its contents. This function can be extremely expensive depending on the + response time of the file system. It should only be used in start up. +

    + +