title: node.js fs.read() example
body: <pre><code>app=function(req,res)
  {
   res.writeHead(200,{'Content-Type':'text/plain'})
   var buffer=new Buffer(100)
   var fs=require('fs')
   fs.open('.'+req.url,'r',function(err,fd){
    fs.fstat(fd,function(err, stats){
     var i=0
     var s=stats.size
     console.log('.'+req.url+' '+s)
     for(i=0;i&lt;s;console.log(i)){
      i=i+buffer.length
      fs.read(fd,buffer,0,buffer.length,i,function(e,l,b){
       res.write(b.toString('utf8',0,l))
       console.log(b.toString('utf8',0,l))
      })
     }
     res.end()
     fs.close(fd)
    })
   })
  }
  http = require('http')
  server = http.createServer(app)
  server.listen(8000,"127.0.0.1")
  console.log('GET http://127.0.0.1:8000/appwsgi/www/index.htm')
  </code></pre>
  
  <p>Why does this only show the last 100 bytes multiple times from a 979 bytes file?</p>
  
  <p>Why does chrome browser not show any output?</p>
  
  <pre><code>gert@node:~/http$ node server.js 
  GET http://127.0.0.1:8000/appwsgi/www/index.htm
  ./appwsgi/www/index.htm 979
  100
  200
  300
  400
  500
  600
  700
  800
  900
  1000
  "vi/vi.htm"&gt;vi&lt;/a&gt; Edit online files on the server.
    &lt;/div&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  
  oad.&lt;br/&gt;
     &lt;a href=
  "vi/vi.htm"&gt;vi&lt;/a&gt; Edit online files on the server.
    &lt;/div&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  
  oad.&lt;br/&gt;
     &lt;a href=
  "vi/vi.htm"&gt;vi&lt;/a&gt; Edit online files on the server.
    &lt;/div&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  
  oad.&lt;br/&gt;
     &lt;a href=
  "vi/vi.htm"&gt;vi&lt;/a&gt; Edit online files on the server.
    &lt;/div&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  
  oad.&lt;br/&gt;
     &lt;a href=
  "vi/vi.htm"&gt;vi&lt;/a&gt; Edit online files on the server.
    &lt;/div&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  
  oad.&lt;br/&gt;
     &lt;a href=
  "vi/vi.htm"&gt;vi&lt;/a&gt; Edit online files on the server.
    &lt;/div&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  
  oad.&lt;br/&gt;
     &lt;a href=
  "vi/vi.htm"&gt;vi&lt;/a&gt; Edit online files on the server.
    &lt;/div&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  
  oad.&lt;br/&gt;
     &lt;a href=
  "vi/vi.htm"&gt;vi&lt;/a&gt; Edit online files on the server.
    &lt;/div&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  
  oad.&lt;br/&gt;
     &lt;a href=
  "vi/vi.htm"&gt;vi&lt;/a&gt; Edit online files on the server.
    &lt;/div&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>