• Stars
    star
    129
  • Rank 277,865 (Top 6 %)
  • Language
    C
  • Created over 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

High performance nodejs http/https static file handler,using c++ addon and libuv lib

ifile(fast and simple nodejs http/https static file module)Build Status

ifile is a simple static http/https handler module, build with libuv and c++.

the module are also be used in express and flat.js framework.

Installing the module

With npm:

ifile module is supported windows, linux, mac.

Make sure, node-gyp has installed.

 npm install ifile

From source:

 git clone https://github.com/DoubleSpout/ifile.git
 cd ifile
 node-gyp rebuild

To include the module in your project:

 var ifile = require('ifile');

##benchmark send the same js file, 6KB size.

  nginx 
  ab -c 100 -n 20000 http://192.168.28.5:8124/js/test.js
  Requests per second:    2634.31 [#/sec] (mean)

  ab -c 500 -n 20000 http://192.168.28.5:8124/js/test.js
  Requests per second:    1886.92 [#/sec] (mean)

  ab -c 800 -n 20000 http://192.168.28.5:8124/js/test.js
  Requests per second:    2033.45 [#/sec] (mean)

  ab -c 500 -n 20000 -H "Accept-Encoding: gzip" http://192.168.28.5:8124/js/test.js
  Requests per second:    2029.59 [#/sec] (mean)


  ifile
  ab -c 100 -n 20000 http://192.168.28.5:8125/js/test.js
  Requests per second:    2077.29 [#/sec] (mean)

  ab -c 500 -n 20000 http://192.168.28.5:8125/js/test.js
  Requests per second:    1880.00 [#/sec] (mean)

  ab -c 800 -n 20000 http://192.168.28.5:8125/js/test.js
  Requests per second:    1791.16 [#/sec] (mean)

  ab -c 500 -n 20000 -H "Accept-Encoding: gzip" http://192.168.28.5:8125/js/test.js
  Requests per second:    1858.01 [#/sec] (mean)


  express
  ab -c 100 -n 20000 http://192.168.28.5:8126/js/test.js
  Requests per second:    915.21 [#/sec] (mean)

  ab -c 500 -n 20000 http://192.168.28.5:8126/js/test.js
  Requests per second:    858.89 [#/sec] (mean)

  ab -c 800 -n 20000 http://192.168.28.5:8126/js/test.js
  Requests per second:    668.99 [#/sec] (mean)

  ab -c 500 -n 20000 -H "Accept-Encoding: gzip" http://192.168.28.5:8126/js/test.js
  Requests per second:    677.11 [#/sec] (mean)



  express+ifile
  ab -c 100 -n 20000 http://192.168.28.5:8127/js/test.js
  Requests per second:    1684.85 [#/sec] (mean)

  ab -c 500 -n 20000 http://192.168.28.5:8127/js/test.js
  Requests per second:    1717.32 [#/sec] (mean)

  ab -c 800 -n 20000 http://192.168.28.5:8127/js/test.js
  Requests per second:    1399.09 [#/sec] (mean)

  ab -c 500 -n 20000 -H "Accept-Encoding: gzip" http://192.168.28.5:8127/js/test.js
  Requests per second:    1468.06 [#/sec] (mean)

example

var ifile = require('ifile')

var http = require('http')

ifile.add([

 ["/static",__dirname,['js','css','jpg']],

],function(req,res,is_static){

	res.statusCode = 404;

    res.end('404')

})

var http = require('http');

http.createServer(function (req, res) {

  ifile.route(req,res);

}).listen(8124);

then request the 127.0.0.1:8124/static/xxx.js

if you have a file in __dirname/static/xxx.js then you will see it.

##API

ifile.add(routearray,not_match_callback);

ifile.route(req,res); route the request

routearray:

[ [request_url_prefix, static_folder [,support_extensions_array]], ... ]

example:

  [
  	["/static",__dirname,['js','css','jpg']],
  	["/static2",__dirname],
  	["/skin","static",['js','css','jpg']]   //static folder will be __dirname+'/'+static
  ]

not_match_function: if ifile not match the request,the not_match_function will be called.It has three parameters,req, res and is_static. for example if add ["/static2",__dirname] 1,request "/user/aaa" will call the not_match_function,and is_static param will be 0; 2,request "/static/not_exist_file" will call the not_match_function,and is_static param will be 1;

##options set ifile.options property to change the default options,for example:

  var ifile = require('ifile');
  ifile.options = {
    expired:86400*100*30,
    gzip:false
  }

default options is that:

  default_options = {
    pipe_szie : 1024*1024*20, //超过20MB的静态文件使用pipe传输不读入内存
    expired : 86400*1000,     //cache-control : max-age=86400
    gzip : true,              //是否开启gzip
    gzip_min_size : 1024,       //开启gzip的文件必须大于等于1024byte
    gzip_file : ['js','css','less','html','xhtml','htm','xml','json','txt'], //gzip压缩的文件后缀名
    gzip_level : 9, //-1表示使用默认值
  }

more example see /test/main.js

##expressjs example

  var express = require('express');
  var app = express();
  var ifile = require("ifile");
  app.use(ifile.connect()); 
  //default is [['/static',__dirname]];

  app.listen(3000);

More Repositories

1

threadAndPackage

threadAndPackage book
JavaScript
582
star
2

ccap

node.js generate captcha using c++ library CImg without install any other lib or software
C
481
star
3

rrestjs

High performance nodejs framework
JavaScript
323
star
4

wujb

node.js blog website
JavaScript
135
star
5

node-threads-a-gogo2

Cross platform Simple and fast JavaScript threads for Node.js
C
119
star
6

phonegap_baidu_sdk_location

phonegap baidu sdk location for android
Java
53
star
7

nodeInAction

nodeInAction2
JavaScript
48
star
8

lua-resty-aries

openresty and lua multi-function template
Lua
47
star
9

etagSession

etagSession nodejs session
JavaScript
40
star
10

libuv_ex

libuv_ex
C++
19
star
11

BaiduTec

BaiduTec share ppt source
JavaScript
17
star
12

express_spout

http://spout.cnodejs.net/
JavaScript
14
star
13

ClusterPlus

Auto load js file,Auto restart child process, Multi child process listen multi port
JavaScript
13
star
14

nodeLibuvThread

nodeLibuvThread
C++
13
star
15

tornado_mvc

tornado_mvc example use sqlalchemy
Python
11
star
16

iroute

iroute
C++
11
star
17

ngxlua_openapi

nginx_lua_OpenApi
Lua
10
star
18

ariestp

node.js async template using ejs tameplate language
JavaScript
10
star
19

nodeClientSession

nodeClientSession
C
9
star
20

node-hvalidator

node-hvalidator
C
8
star
21

resty-mgo3

easy way to use mongodb 3.x with openresty
Lua
7
star
22

google--circle

山寨谷歌+圈子的特效
JavaScript
7
star
23

tryMenu

tryMenu
Lua
6
star
24

SQLAlchemy_Demo

SQLAlchemy_Demo
Python
6
star
25

picture_riddle_game

picture_riddle_game
JavaScript
5
star
26

AsyncProxy_browser

异步代理前端浏览器版本,ajax并发回调和ajax队列
JavaScript
5
star
27

RestSpout

Restful node.js web framework
JavaScript
5
star
28

node.js---AsyncProxy

AsyncProxy node.js不再异步嵌套代码
JavaScript
5
star
29

excel2json

save excel file to json file
Python
4
star
30

dsblog

HTML
3
star
31

dockerDemo

docker code demo python and node.js
Python
2
star
32

jenkinsNodejs

jenkins Nodejs publish test
JavaScript
2
star
33

siegeServer

siegeServer
Python
2
star
34

GolangStudySource

GolangStudySource
Go
2
star
35

jquery.spout.ajaxpage

基于jquery的ajax分页插件,只提供原始功能,无DOM功能
JavaScript
2
star
36

download_statis

download_statis
C
2
star
37

flask_mvc

python flask simple mvc folder
Python
1
star
38

flask_restapi_example

flask restapi example using flask-restful
Python
1
star
39

scrapy_outlets

python scrapy example
Python
1
star
40

vipsystem

vipsystem
Python
1
star
41

flask_kendoui_demo

flask_kendoui_demo
Python
1
star
42

wx_widget_sdk

wx_widget_sdk
JavaScript
1
star
43

wx_vote_client

wx_vote_client
CSS
1
star
44

szhouse

JavaScript
1
star