Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
filed - Simplified file library
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mikeal Rogers  
View profile  
 More options Oct 27 2011, 11:14 pm
From: Mikeal Rogers <mikeal.rog...@gmail.com>
Date: Thu, 27 Oct 2011 20:14:24 -0700
Local: Thurs, Oct 27 2011 11:14 pm
Subject: filed - Simplified file library

I've been talking about this forever but I finally wrote it and have been using it on a non-public project for a few weeks now.

Released it today. Basically it's a full file server in a single object. It's kind of like request for files.

https://github.com/mikeal/filed

# filed -- Simplified file library.

npm install filed

## Super simple to use

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.

filed('/myfile').pipe(fs.createWriteStream('/out'))

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.

http.createServer(function (req, resp) {
  filed('/data.json').pipe(resp)

})

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.

http.createServer(function (req, resp) {
  req.pipe(filed('/newfile')).pipe(resp)

})

When accepting a PUT request data will be streamed to the file and a 201 status will be sent on the HTTP Response when the upload is finished.

During a GET request a 404 Response will be sent if the file does not exist.

http.createServer(function (req, resp) {
  req.pipe(filed('/data.json')).pipe(resp)

})

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.

http.createServer(function (req, resp) {
  req.pipe(filed('/directory')).pipe(resp)

})

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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dominic Tarr  
View profile  
 More options Oct 27 2011, 11:27 pm
From: Dominic Tarr <dominic.t...@gmail.com>
Date: Fri, 28 Oct 2011 14:27:30 +1100
Local: Thurs, Oct 27 2011 11:27 pm
Subject: Re: [nodejs] filed - Simplified file library

oh, wow. this is awesome.

and not a callback in sight.

see every one! streams kick ass!

On Fri, Oct 28, 2011 at 2:14 PM, Mikeal Rogers <mikeal.rog...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jorge  
View profile  
 More options Oct 28 2011, 3:19 am
From: Jorge <jo...@jorgechamorro.com>
Date: Fri, 28 Oct 2011 09:19:50 +0200
Local: Fri, Oct 28 2011 3:19 am
Subject: Re: [nodejs] filed - Simplified file library
On 28/10/2011, at 05:27, Dominic Tarr wrote:

> oh, wow. this is awesome.

> and not a callback in sight.

> see every one! streams kick ass!

Yeah... streams kick ass for streaming.
--
Jorge.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dominic Tarr  
View profile  
 More options Oct 28 2011, 8:16 am
From: Dominic Tarr <dominic.t...@gmail.com>
Date: Fri, 28 Oct 2011 23:16:50 +1100
Local: Fri, Oct 28 2011 8:16 am
Subject: Re: [nodejs] filed - Simplified file library

you are mad to try to stream stuff any other way!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pedro Teixeira  
View profile  
 More options Oct 28 2011, 10:37 am
From: Pedro Teixeira <pedro.teixe...@gmail.com>
Date: Fri, 28 Oct 2011 07:37:58 -0700 (PDT)
Local: Fri, Oct 28 2011 10:37 am
Subject: Re: filed - Simplified file library
Mikeal keeps simplifying everyday Node.
Thanks again!

On Oct 28, 4:14 am, Mikeal Rogers <mikeal.rog...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Isaac Schlueter  
View profile  
 More options Oct 28 2011, 11:47 am
From: Isaac Schlueter <i...@izs.me>
Date: Fri, 28 Oct 2011 08:47:01 -0700
Local: Fri, Oct 28 2011 11:47 am
Subject: Re: [nodejs] Re: filed - Simplified file library
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')`?

>> 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?

>> http.createServer(function (req, resp) {
>>   req.pipe(filed('/directory')).pipe(resp)

>> })

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

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mikeal Rogers  
View profile  
 More options Oct 28 2011, 11:54 am
From: Mikeal Rogers <mikeal.rog...@gmail.com>
Date: Fri, 28 Oct 2011 08:54:40 -0700
Local: Fri, Oct 28 2011 11:54 am
Subject: Re: [nodejs] Re: filed - Simplified file library

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

>>> http.createServer(function (req, resp) {
>>>   req.pipe(filed('/directory')).pipe(resp)

>>> })

>>> 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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joshua Cohen  
View profile  
 More options Oct 28 2011, 11:58 am
From: Joshua Cohen <defea...@gmail.com>
Date: Fri, 28 Oct 2011 10:58:22 -0500
Local: Fri, Oct 28 2011 11:58 am
Subject: Re: [nodejs] Re: filed - Simplified file library

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:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nicolas Chambrier  
View profile  
 More options Oct 29 2011, 6:10 pm
From: Nicolas Chambrier <naho...@gmail.com>
Date: Sat, 29 Oct 2011 15:10:00 -0700 (PDT)
Subject: Re: filed - Simplified file library

Impressive work. API is quite neat, it's a pleasure working with this.

Congratulations and many thanks for your work!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »