REBOL3 tracker
  0.9.12 beta
Ticket #0001684 User: anonymous

Project:



rss
TypeWish Statustested Date20-Oct-2010 13:06
Versionalpha 107 CategoryMezzanine Submitted byBrianH
PlatformAll Severitymajor Priorityhigh

Summary Script header length field and SAVE /length option
Description The 'length field of a script header would allow a loader to stop loading before the end of the file. This would enable another kind of script embedding that - unlike script-in-a-block - wouldn't require the decoding of the whole script in order to know where the script ends. This would especially be useful for binary script aggregate files.

Another advantage over script-in-a-block embedding is that you could support binary-encoded compressed embedded scripts (see #1466). With script-in-a-block only script-encoded compression is supported.

SAVE would get a /length option to turn this on, or you could provide your own header to SAVE with a 'length field set to any TRUE? value. This will allow you to save a file with a length automatically if it had a length before you used LOAD/header to load it.

The length starts after the CRLF/CR/LF after the REBOL header, and ends at the end of the data. For compressed scripts, it is the length of the compressed data. The length is binary, and will be messed up if you change the line endings (after the first one after the header).
Example code
>> save/length none [print "Hello REBOL!"]
== {REBOL [
    length: 21
]
print "Hello REBOL!"
}

Assigned ton/a Fixed inalpha 108 Last Update21-Oct-2010 07:03


Comments
(0002638)
BrianH
20-Oct-2010 13:08

In alpha 108 this is implemented in SAVE and sys/load-header. There is no code yet that takes advantage of this feature to make script agregates, but user code to do this is possible.
(0002639)
Gregg
20-Oct-2010 19:54

So saving length with compressed scripts makes them non-portable unless the whole thing is always handled a binary, end-to-end, correct?
(0002643)
BrianH
21-Oct-2010 07:03

Correct. But that also goes for script-encoded-compressed or uncompressed scripts if you change the line endings from CR or LF to CRLF, or vice versa. The same goes for the checksum of uncompressed scripts, but more so: Any change to the line ending is treated as corruption. The checksum of compressed scripts isn't affected though, and script-encoded compressed scripts can even be transmitted in text mode, as long as you don't use the length field.

The length field is primarily designed to allow binary aggregates of multiple scripts and other binary data types (like jpegs). It's definitely more efficient than script-in-a-block for this kind of thing. We don't yet have a multi-loader for data in that format, but a108+ would make this kind of thing easy to create.

All of the length, compression and checksum option treat R3 scripts as binary code. In some cases some exceptions or workarounds have been added, but for the most part R3 source is to be considered binary. Fortunately, READ returns a binary.

If it makes you feel better, SAVE doesn't currently save with platform-specific line endings; it always saves with LF. As long as you use a line-ending preserving text editor and set your web server to serve up REBOL scripts as binary, all should work great.

Date User Field Action Change
21-Oct-2010 07:09 BrianH Comment : 0002643 Modified -
21-Oct-2010 07:06 BrianH Comment : 0002643 Modified -
21-Oct-2010 07:03 BrianH Comment : 0002643 Added -
20-Oct-2010 19:54 Gregg Comment : 0002639 Added -
20-Oct-2010 13:08 BrianH Comment : 0002638 Added -
20-Oct-2010 13:06 BrianH Description Modified -
20-Oct-2010 13:06 BrianH Code Modified -
20-Oct-2010 13:06 BrianH Fixedin Modified => alpha 108
20-Oct-2010 13:06 BrianH Status Modified submitted => tested
20-Oct-2010 13:06 BrianH Ticket Added -