Browse Source

add blockingFileRead to tide me over until I can get a proper file interface.

v0.7.4-release
Ryan 16 years ago
parent
commit
16ef5029de
  1. 17
      node.cc
  2. 27
      spec/index.html

17
node.cc

@ -57,6 +57,8 @@ ReadFile (const string& name)
return result; return result;
} }
static void static void
ParseOptions (int argc, char* argv[], map<string, string>& options, string* file) ParseOptions (int argc, char* argv[], map<string, string>& options, string* file)
{ {
@ -121,6 +123,17 @@ LogCallback (const Arguments& args)
return Undefined(); return Undefined();
} }
static Handle<Value>
BlockingFileReadCallback (const Arguments& args)
{
if (args.Length() < 1) return v8::Undefined();
HandleScope scope;
String::Utf8Value filename(args[0]);
return ReadFile (*filename);
}
static void static void
OnFatalError (const char* location, const char* message) OnFatalError (const char* location, const char* message)
{ {
@ -153,6 +166,10 @@ main (int argc, char *argv[])
Local<Object> g = Context::GetCurrent()->Global(); Local<Object> g = Context::GetCurrent()->Global();
g->Set( String::New("log"), FunctionTemplate::New(LogCallback)->GetFunction()); g->Set( String::New("log"), FunctionTemplate::New(LogCallback)->GetFunction());
g->Set( String::New("blockingFileRead")
, FunctionTemplate::New(BlockingFileReadCallback)->GetFunction()
);
Init_timer(g); Init_timer(g);
Init_tcp(g); Init_tcp(g);
Init_http(g); Init_http(g);

27
spec/index.html

@ -3,6 +3,8 @@
<head> <head>
<title>Node API</title> <title>Node API</title>
<link href="specification.css" rel=stylesheet> <link href="specification.css" rel=stylesheet>
<!-- <link href="http://www.whatwg.org/style/specification"
rel=stylesheet> -->
<body class=draft> <body class=draft>
<div class=head> <div class=head>
@ -52,6 +54,8 @@
</ul> </ul>
<li><a href="index.html#tcp_client"><span class=secno>3 </span>TCP Client</a> <li><a href="index.html#tcp_client"><span class=secno>3 </span>TCP Client</a>
<li><a href="index.html#timers"><span class=secno>4 </span>Timers</a> <li><a href="index.html#timers"><span class=secno>4 </span>Timers</a>
<li><a href="index.html#blocking"><span class=secno>5 </span>Blocking
Functions</a>
</ul> </ul>
<!--end-toc--> <!--end-toc-->
@ -241,3 +245,26 @@ will be made.
</dd> </dd>
</dl> </dl>
<h2 id=blocking><span class=secno>5 </span>Blocking Functions</h2>
<p>Node includes a number of blocking functions in its API. Some of these
will be removed in the future as the software improves.
<dl>
<dt><code>log(string)</code></dt>
<dd>
<p>This function outputs the string to the stadard output device
(usually the console).
Its speed is dependent on where stdout is piped to.
</dd>
<dt><code>blockingFileRead(filename)</code></dt>
<dd>
<p>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.
</dd>
</dl>

Loading…
Cancel
Save