Several bug fixes/features #11

wants to merge 11 commits into

3 participants



This pull request is kind of messy since some of the features I didn't expect to be pulled in by anyone. Since github doesn't allow cherry picking of requests, i'm making one request, but I've described each commit below so you can pick what you want to merge.

26d808 and 225506:
Adds resume support for single files. It is incomplete in the sense that it does not deal with multiple ranges, so it is only good for resuming a broken download. These are the commits you most likely would NOT want to pull in.

3cf5 to 5800, 7a4022 and 040f1c:
add a stripPrefix option to deal with routing. Consider for example that you've setup routes such that all URLs of type '/download/file' go to a node-static instance created with root directory 'download/'. In this case the instance will recieve the path as '/download/file', but should check only for '/file'. A stripPrefix of 'download' will fix that issue.

'binary' is deprecated encoding. Instead we set no encoding, receive a buffer object and do a memcpy() without any decoding to the destination buffer.

self explanatory in the commit message


Fix a bug where stream() always joins with '.' when pathname is passed as null, when we actually want to consider the filenames with respect to the root directory and not the current directory. The current directory of the node process, and the root download directory may be different.

Thanks for a great piece of software to modify.


nikhilm added some commits Oct 18, 2010
@nikhilm nikhilm Added resume support.
If the range header is passed, node-static supports resuming the file.
Currently it can only handle one range per file, so no bytes=100-150,200-250
and it can't do resume when multiple files are requested in one request
@nikhilm nikhilm Support query parameter ns_range instead of range header for a specia…
…l case at my end
@nikhilm nikhilm Added stripPrefix feature.
This allows route based serving using multiple static server
instances and non one to one route->directory mapping
@nikhilm nikhilm Add the prefix '/' back bf87f73
@nikhilm nikhilm Remove debug output 5f00561
@nikhilm nikhilm Fix encoding issue.
encoding can only be ascii, utf8 or base64. Setting it to binary
causes 'data' to emit a string, when we really want a buffer.
Using a buffer we can also use the much faster Buffer.copy
@nikhilm nikhilm Initialize stripPrefix to empty string if not specified 7a4022a
@nikhilm nikhilm Always pass the pathname and file name separately.
If the pathname is passed as null, the file path will be joined with '.'
But if the root and the process current directory are not the same, this
will not work, since we don't want to search the current directory, we want
to search the root
@nikhilm nikhilm In case of a stream error, have a status of 500.
null will cause an invalid error object to be passed on to the user callback.
The status code will be null and the error message will be null and hence not 'toString'able
@nikhilm nikhilm Ensure non empty stripPrefix 040f1c5
@nikhilm nikhilm Merge branch 'master' of git://

@cloudhead can you consider pulling this in? The range/resume support in particular is very useful. Where I work, we're running into issues in using HTML5 audio because webkit does range requests for the files, and if they do not get handled 'properly', will only play a file once. (ref: )


@nikhilm: seems your patches break the caching. It uses the pathname as a key for the cache, and your patches split out the filename. So multiple files served from the same directory get in each other's way in the cache.

@phstc phstc closed this Apr 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment