Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] [Fwd: SKIPping in a file]

From: joel:neely:fedex at: 8-Jul-2001 5:55

Hello, all! Since Jeff had motivated me to dig out R/CUG2.3 and read up on /DIRECT, I thought I'd take a shot at revising the "line reduction" script for Aaron to read only the amount of data necessary for the sample. (Not that I've ever been known to run an idea into the ground! ;-) In the course of playing with that idea, I ran into a puzzler that I haven't sorted out yet. Any suggestions would be most welcome! This function readhead: func [fn [file!] n [integer!] /local fi mybuf] [ fi: open/binary/direct fn mybuf: copy/part fi n close fi mybuf ] seems to do what I want -- read/return the first N bytes from FN (as a BINARY! value, of course, but that's a non-issue for the task at hand). However, *this* function readtail: func [fn [file!] n [integer!] /local sz rp fi mybuf] [ sz: get in info? fn 'size rp: sz + 1 - n print [sz rp] fi: open/binary/direct fn fi: skip fi rp mybuf: copy/part fi n close fi mybuf ] seems to perform the calculations for where to position into the file (as witnessed by the debugging output from the first three lines), but then hangs (immune to the escape key). It's burning CPU cycles furiously according to top, but at least responds to kill -15. Trying a different approach, *this* function readtailx: func [fn [file!] n [integer!] /local sz rp fi mybuf] [ sz: get in info? fn 'size rp: sz + 1 - n print [sz rp] fi: open/direct/binary/skip fn rp mybuf: copy/part fi n close fi mybuf ] again shows the correct size/readpoint calculations, but always returns the *first* N bytes of the file, not the *last* N bytes. Am I misreading R/CUG or doing something boneheaded here? Or are /SKIP and SKIP broken in View 1.2.0.4.2 ? -jn- --------------------------------------------------------------- There are two types of science: physics and stamp collecting! -- Sir Arthur Eddington joel-dot-neely-at-fedex-dot-com