Exemple avec node.js fs.read ()

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<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')

Pourquoi est-ce seulement de montrer les 100 derniers octets à plusieurs reprises à partir d'une 979 octets fichier?

Pourquoi ne le navigateur google chrome, de ne pas montrer à n'importe quelle sortie?

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">vi</a> Edit online files on the server.
  </div>
 </body>
</html>

oad.<br/>
   <a href=
"vi/vi.htm">vi</a> Edit online files on the server.
  </div>
 </body>
</html>

oad.<br/>
   <a href=
"vi/vi.htm">vi</a> Edit online files on the server.
  </div>
 </body>
</html>

oad.<br/>
   <a href=
"vi/vi.htm">vi</a> Edit online files on the server.
  </div>
 </body>
</html>

oad.<br/>
   <a href=
"vi/vi.htm">vi</a> Edit online files on the server.
  </div>
 </body>
</html>

oad.<br/>
   <a href=
"vi/vi.htm">vi</a> Edit online files on the server.
  </div>
 </body>
</html>

oad.<br/>
   <a href=
"vi/vi.htm">vi</a> Edit online files on the server.
  </div>
 </body>
</html>

oad.<br/>
   <a href=
"vi/vi.htm">vi</a> Edit online files on the server.
  </div>
 </body>
</html>

oad.<br/>
   <a href=
"vi/vi.htm">vi</a> Edit online files on the server.
  </div>
 </body>
</html>

source d'informationauteur Gert Cuykens | 2011-05-12