Example JS Code - FILE API

2 views
Skip to first unread message

Christoph Dorn

unread,
Sep 17, 2011, 8:44:09 PM9/17/11
to gp...@googlegroups.com
Is there a list of a bunch of sample JS code that works on `gsr` anywhere?

I am specifically looking for how to use the FILE api.

Thanks!
Christoph

Wes Garland

unread,
Sep 17, 2011, 10:23:33 PM9/17/11
to gp...@googlegroups.com
Christoph;

There isn't as much sample JS code floating around for GPSEE as I'd like, as most of the development done with GPSEE is proprietary software.  That said, if there are specific types of examples you're interested in, I can probably find suitable snippets; similarly, I'm hoping to blog and wiki more with better examples in the not-distant future.  Time, however, is a cruel mistress. :)

Now - file API - we have implemented the CommonJS fs-base module, described here: http://wiki.commonjs.org/wiki/Filesystem/A/0

It's a full(?) implementation with a few extensions.  The extensions allow us to do I/O.  I gather you're not a C guy, but the fs-base module (and also the net module) serves as an excellent example for how to create base-level JS level libraries, portably, from the POSIX APIs.   The source code for fs-base is in modules/fs-base/fs-base.js and it's quite readable.

The extensions I spoke of are in the Stream class near the bottom of fs-base.js. It's in fs-base because I was waiting for CommonJS to come up with something like this that works with fs-base, but somehow we got stalled debating module formats for a year.

The interesting methods ATM are read, readln, write, writeln, and close.  They work on GPSEE ByteThings, which are a castable binary type, and have naive toString methods attached.  So they'll work pretty much how you'd expect them to.

These ByteThings can also be cast to either ByteString or ByteArray, which are classes from the CommonJS Binary/B specification.  GPSEE casting works by using ByteThing constructors without the 'new' operand; the result uses the same backing store as the input object, but interpreted by the methods of the output object.

Hm. I realize this is a lot to throw a you at once.  Focus me a bit and I'll find you some better information once we're building on Lion.

Wes
--
Wesley W. Garland
Director, Product Development
PageMail, Inc.
+1 613 542 2787 x 102

Christoph Dorn

unread,
Sep 19, 2011, 12:17:13 PM9/19/11
to gp...@googlegroups.com
Wes Garland wrote:
> There isn't as much sample JS code floating around for GPSEE as I'd
> like, as most of the development done with GPSEE is proprietary
> software. That said, if there are specific types of examples you're
> interested in, I can probably find suitable snippets; similarly, I'm
> hoping to blog and wiki more with better examples in the not-distant
> future. Time, however, is a cruel mistress. :)
>
> Now - file API - we have implemented the CommonJS fs-base module,
> described here: http://wiki.commonjs.org/wiki/Filesystem/A/0
>
> It's a full(?) implementation with a few extensions. The extensions
> allow us to do I/O. I gather you're not a C guy, but the fs-base
> module (and also the net module) serves as an excellent example for
> how to create base-level JS level libraries, portably, from the POSIX
> APIs. The source code for fs-base is in modules/fs-base/fs-base.js
> and it's quite readable.
I'll start there. I don't need much to start.

> The extensions I spoke of are in the Stream class near the bottom of
> fs-base.js. It's in fs-base because I was waiting for CommonJS to come
> up with something like this that works with fs-base, but somehow we
> got stalled debating module formats for a year.
>
> The interesting methods ATM are read, readln, write, writeln, and
> close. They work on GPSEE ByteThings, which are a castable binary
> type, and have naive toString methods attached. So they'll work
> pretty much how you'd expect them to.

All I need is toString() some files to get the loader booted.

> These ByteThings can also be cast to either ByteString or ByteArray,
> which are classes from the CommonJS Binary/B specification. GPSEE
> casting works by using ByteThing constructors without the 'new'
> operand; the result uses the same backing store as the input object,
> but interpreted by the methods of the output object.
>
> Hm. I realize this is a lot to throw a you at once. Focus me a bit
> and I'll find you some better information once we're building on Lion.

See: http://groups.google.com/group/gpsee/msg/8d44cae2b3997d22

I am looking to do (1) as soon as GPSEE works on Lion and (2) as soon as
all relevant APIs are available in GPSEE.
(3) Would be great in the next 3 to 6 months but ideally we move on some
of the CommonJS specs in sync.

I also just found: http://www.page.ca/~wes/opensource/gpsee/

Thanks!
Christoph

Reply all
Reply to author
Forward
0 new messages