UNSAFE MODULE; IMPORT FS, File, OSError, Text; CONST N = 16_1000000; (* == 2^24 == 16MBytes *) TYPE Ptr = UNTRACED REF ARRAY [0..N-1] OF File.Byte; PROCEDURE Buf FromFile (path: TEXT; pad: CARDINAL): T = VAR f: File.T; len, next, got: INTEGER; t: T; p: Ptr; BEGIN TRY f := FS.OpenFileReadonly (path); len := VAL(f.status().size, INTEGER); t := NEW (T, len + pad); next := 0; WHILE (len > N) DO p := LOOPHOLE (ADR (t[next]), Ptr); got := f.read (p^, mayBlock := TRUE); INC (next, got); DEC (len, got); END; WHILE (len > 0) DO p := LOOPHOLE (ADR (t[next]), Ptr); got := f.read (SUBARRAY (p^, 0, len), mayBlock := TRUE); INC (next, got); DEC (len, got); END; f.close (); RETURN t; EXCEPT OSError.E => RETURN NIL; END; END FromFile; PROCEDUREFromText (txt: TEXT): T = VAR t := NEW (T, Text.Length (txt)); BEGIN Text.SetChars (t^, txt); RETURN t; END FromText; BEGIN <*ASSERT BYTESIZE (File.Byte) = BYTESIZE (CHAR) *> END Buf.