[futurebasic] Re: [FB] Raw resources

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : May 1999 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Fri, 14 May 1999 19:17:38 -0500

Sean -G3- wrote:

> I'm trying to open a resource file as raw data, then read/write to/from
> it. I'm doing this for downloading & uploading in my communications
> program. I found out, from the people @ pixmix, how to do the opening
> part.

> I now need to know how to read/write. Here is my routine for opening
> resource files:
>
> --------------------------
> 'Format for opening *raw* resources
> 'osErr% = FN HOPENRF (pbPtr&)
>
> CLEAR LOCAL
> LOCAL FN GetParam$ (fsName$, fsVRefNum%)
>   DIM 255 ParamBlock$
>   DIM fsVRefNum%, 63 fsName$
>
>   pbPtr& = @ParamBlock$
>
>   pbPtr&.ioCompletion&   = 0'   NO IOCOMPLETION
>   pbPtr&.ioNamePtr&      = @fsName$'   FILENAME TO READ
>   pbPtr&.ioVRefNum%      = fsVRefNum%'   VOLUME TO READ
>   pbPtr&.ioFDirIndex%    = 0'   DEFAULT DRIVE
>
>   GET FILE INFO ParamBlock$
> END FN = ParamBlock$
>
> WINDOW 1
> filename$=FILES$(_fOpen,,,volRef%)
> param$ = FN GetParam$ (filename$,volRef%)
> paramPointer& = @param$
> err% = FN HOPENRF(paramPointer&)
>
> DO
>   HANDLEEVENTS
> UNTIL gProgramEnds
> --------------------------

What you have looks like it'll work, but this way is easier:

OPEN "RR", #fileID, fsName$,,fsVRefNum%

In the "RR" parameter, the first "R" stands for "Random access" (you can also
use "I" or "O" here), and the 2nd "R" stands for "Resource fork."

You can then use FB's normal file i/o commands (like READ FILE and WRITE FILE)
to read from & write to the resource fork.  Using OPEN also has the added
benefit that it will create the resource fork for you if it doesn't already
exist.  (HOPENRF won't do that; you'd have to call CREATERESFILE first.)

- Rick