Filed does a lazy stat call so you can actually open a file and being writing to it and if the file isn't there it will just be created.
var request = require('filed'); var f = filed('/newfile') f.write('test') f.end()
## Streaming
The returned file object is a stream so you can do standard stream stuff to it. Based on *what* you do the object it will be a read stream, a write stream.
So if you send data to it, it'll be a write stream.
fs.createReadStream(filed('/newfile'))
If you pipe it to a destination it'll be a read stream.
And of course you can pipe a filed object from itself to itself and it'll figure it out.
filed('/myfile').pipe(filed('/newfile'))
Those familiar with [request](http://github.com/mikeal/request) will be familiar seeing object capability detection when doing HTTP. filed does this as well.
Not only does the JSON file get streamed to the HTTP Response it will include an Etag, Last-Modified, Content-Length, and a Content-Type header based on the filed extension.
The Etag and Last-Modified headers filed creates are based solely on the stat() call so if you pipe a request to an existing file the cache control headers will be taken in to account a 304 response will be sent if the cache control headers match a new stat() call. This can be very helpful in avoiding unnecessary disc reads.
Just to round out the full feature set and make it full file server if you give filed an existing directory it will actually check for an index.html file in that directory and serve it if it exists.
> Filed does a lazy stat call so you can actually open a file and being > writing to it and if the file isn't there it will just be created.
> var request = require('filed'); > var f = filed('/newfile') > f.write('test') > f.end()
> ## Streaming
> The returned file object is a stream so you can do standard stream stuff to > it. Based on *what* you do the object it will be a read stream, a write > stream.
> So if you send data to it, it'll be a write stream.
> fs.createReadStream(filed('/newfile'))
> If you pipe it to a destination it'll be a read stream.
> And of course you can pipe a filed object from itself to itself and it'll > figure it out.
> filed('/myfile').pipe(filed('/newfile'))
> Those familiar with [request](http://github.com/mikeal/request) will be > familiar seeing object capability detection when doing HTTP. filed does this > as well.
> Not only does the JSON file get streamed to the HTTP Response it will > include an Etag, Last-Modified, Content-Length, and a Content-Type header > based on the filed extension.
> The Etag and Last-Modified headers filed creates are based solely on the > stat() call so if you pipe a request to an existing file the cache control > headers will be taken in to account a 304 response will be sent if the cache > control headers match a new stat() call. This can be very helpful in > avoiding unnecessary disc reads.
> Just to round out the full feature set and make it full file server if you > give filed an existing directory it will actually check for an index.html > file in that directory and serve it if it exists.
> Filed does a lazy stat call so you can actually open a file and being writing to it and if the file isn't there it will just be created.
> var request = require('filed');
> var f = filed('/newfile')
> f.write('test')
> f.end()
> ## Streaming
> The returned file object is a stream so you can do standard stream stuff to it. Based on *what* you do the object it will be a read stream, a write stream.
> So if you send data to it, it'll be a write stream.
> fs.createReadStream(filed('/newfile'))
> If you pipe it to a destination it'll be a read stream.
> And of course you can pipe a filed object from itself to itself and it'll figure it out.
> filed('/myfile').pipe(filed('/newfile'))
> Those familiar with [request](http://github.com/mikeal/request) will be familiar seeing object capability detection when doing HTTP. filed does this as well.
> Not only does the JSON file get streamed to the HTTP Response it will include an Etag, Last-Modified, Content-Length, and a Content-Type header based on the filed extension.
> The Etag and Last-Modified headers filed creates are based solely on the stat() call so if you pipe a request to an existing file the cache control headers will be taken in to account a 304 response will be sent if the cache control headers match a new stat() call. This can be very helpful in avoiding unnecessary disc reads.
> Just to round out the full feature set and make it full file server if you give filed an existing directory it will actually check for an index.html file in that directory and serve it if it exists.
I'm probably going to integrate with this in my tar thingie.
On Fri, Oct 28, 2011 at 07:37, Pedro Teixeira <pedro.teixe...@gmail.com> wrote: >> var request = require('filed'); >> var f = filed('/newfile') >> f.write('test') >> f.end()
Assuming that should be `var filed = require('filed')`?
>> fs.createReadStream(filed('/newfile'))
Am I reading this right? You're passing a filed response to createReadStream? Some kind of toString magic, or should there be a .pipe() in there somewhere, or flip the nesting?
>> Just to round out the full feature set and make it full file server if you give filed an existing directory it will actually check for an index.html file in that directory and serve it if it exists.
The only thing missing is filed.createServer('/directory').listen(80)
On Oct 28, 2011, at October 28, 20118:47 AM, Isaac Schlueter wrote:
> Yeah, this is super badass. Nicely done, Mikeal.
> I'm probably going to integrate with this in my tar thingie.
> On Fri, Oct 28, 2011 at 07:37, Pedro Teixeira <pedro.teixe...@gmail.com> wrote: >>> var request = require('filed'); >>> var f = filed('/newfile') >>> f.write('test') >>> f.end()
> Assuming that should be `var filed = require('filed')`?
yeah, i got two pull requests for that doc bug 10 minutes after release :) fixed.
>>> fs.createReadStream(filed('/newfile'))
> Am I reading this right? You're passing a filed response to > createReadStream? Some kind of toString magic, or should there be a > .pipe() in there somewhere, or flip the nesting?
whoops, yeah, that should be .pipe(filed('/newfile'))
>>> Just to round out the full feature set and make it full file server if you give filed an existing directory it will actually check for an index.html file in that directory and serve it if it exists.
> The only thing missing is filed.createServer('/directory').listen(80)
i rarely, if ever, what to create a server that *only* serves static files. i could add this easily, and might, but the framework i've been building (which is also being used for this non-public project) has a really nice api for serving files for a route and uses filed under the hood. that will be released eventually as well.
Serving only static files is conditionally very useful, mostly in development environments when you need an easy way to share something you've been working on with other devs (c.f. Python's SimpleHTTPServer).
On Fri, Oct 28, 2011 at 10:54 AM, Mikeal Rogers <mikeal.rog...@gmail.com>wrote:
> On Oct 28, 2011, at October 28, 20118:47 AM, Isaac Schlueter wrote:
> > Yeah, this is super badass. Nicely done, Mikeal.
> > I'm probably going to integrate with this in my tar thingie.
> > On Fri, Oct 28, 2011 at 07:37, Pedro Teixeira <pedro.teixe...@gmail.com> > wrote: > >>> var request = require('filed'); > >>> var f = filed('/newfile') > >>> f.write('test') > >>> f.end()
> > Assuming that should be `var filed = require('filed')`?
> yeah, i got two pull requests for that doc bug 10 minutes after release :) > fixed.
> >>> fs.createReadStream(filed('/newfile'))
> > Am I reading this right? You're passing a filed response to > > createReadStream? Some kind of toString magic, or should there be a > > .pipe() in there somewhere, or flip the nesting?
> whoops, yeah, that should be .pipe(filed('/newfile'))
> >>> Just to round out the full feature set and make it full file server if > you give filed an existing directory it will actually check for an > index.html file in that directory and serve it if it exists.
> > The only thing missing is filed.createServer('/directory').listen(80)
> i rarely, if ever, what to create a server that *only* serves static files. > i could add this easily, and might, but the framework i've been building > (which is also being used for this non-public project) has a really nice api > for serving files for a route and uses filed under the hood. that will be > released eventually as well.