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;
}
static void
ParseOptions (int argc, char* argv[], map<string, string>& options, string* file)
{
@ -121,6 +123,17 @@ LogCallback (const Arguments& args)
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
OnFatalError (const char* location, const char* message)
{
@ -153,6 +166,10 @@ main (int argc, char *argv[])
Local<Object> 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);

27
spec/index.html

@ -3,6 +3,8 @@
<head>
<title>Node API</title>
<link href="specification.css" rel=stylesheet>
<!-- <link href="http://www.whatwg.org/style/specification"
rel=stylesheet> -->
<body class=draft>
<div class=head>
@ -52,6 +54,8 @@
</ul>
<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#blocking"><span class=secno>5 </span>Blocking
Functions</a>
</ul>
<!--end-toc-->
@ -241,3 +245,26 @@ will be made.
</dd>
</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