On Jul 30, 2013, at 16:59, raisch <[email protected]> wrote:

>> On the server side, I also don't want to depend on express or other big 
>> system. On the server side, I just need to load a file on the local 
>> filesystem; I don't need to involve any HTTP layer. 
> 
> How would you expect to get the data to the client without using HTTP? 

Perhaps I should have said "using node" instead of "on the server". The node 
process needn't be a server. There needn't be a client connecting to it.


On Jul 30, 2013, at 17:00, raisch <[email protected]> wrote:

> You may wish to study XMLHttpRequest Call - Ajax Patterns which presents both 
> the mechanisms used by Ajax as well as a pared-down implementation of 
> something like jQuery's get() called 'AjaxCaller'

I know how to use XMLHttpRequest and have already written a loadFile function 
using it. But that's only necessary when running in a browser. I have found 
XMLHttpRequest implementations for node in npm which I could include, but all I 
really want when running in node is for loadFile to load the file from the 
local filesystem using fs.readSync or equivalent.


On Jul 30, 2013, at 17:04, Michael Ryan <[email protected]> wrote:

> For the server-side portion, you just need to use a static-files module.

I think I've confused things by using the word "server". I do not need to serve 
static files.

Let me explain again. I am writing a JavaScript library. I converts text files 
in a particular format into images. It is designed to be used in the browser, 
but now I am enhancing it so that it can also work in node. The user can 
acquire the contents of the text file using whatever method and feed it to my 
library. But I also want to offer a convenience function that will accept a 
filename. If the library is running in the browser, it should use 
XMLHttpRequest or equivalent to download the file from the server (same origin 
restriction is fine). If running in node, it should use fs.readSync or similar 
to read the file from the local filesystem. This seems like an extremely simple 
and natural thing to want to do (what could be simpler than wanting to read in 
a text file?), therefore I expected to find a module already written ages ago 
to do that.


> As to file encoding, I would recommend having all your text files in UTF-8 
> without a Byte Order Marker (BOM), many utils blow up without them, and many 
> editors in windows by default inject them for new files, so that's something 
> to be aware of.

I would also recommend UTF-8, and I am considering mandating that. However, 
ideally I want to support all of the features that the text file format I am 
using allows, and one of those features is that the text file could be in 
either UTF-8 or ISO-8859-1 encoding, as indicated by a particular line in the 
file (much like an HTML file might contain a <meta charset="…"> line).

With fs.readSync, there's an options object which could include an encoding 
flag, but that assumes that I know in advance what the file's encoding is, and 
I do not since the file is provided by the user of my library. So I could leave 
off the encoding, and get back a raw buffer, and deal with that somehow…

With XMLHttpRequest, I'm not sure how it handles encoding; I haven't tested it 
yet. Perhaps it assumes the server sends the correct charset in the 
Content-Type header, but I do not believe that will be reliable for my use 
case. Users will probably just upload these text files to their web space, and 
their web server won't know anything about this particular text file format so 
it won't know what charset to send.

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to