complex http example fix
[k8lst.git] / modules / fileext.st
blob571b71c618cdc32fc8f88f65788febd3c50dd143
2  coded by Ketmar // Invisible Vector (psyc://ketmar.no-ip.org/~Ketmar)
3  Understanding is not required. Only obedience.
5  This program is free software. It comes without any warranty, to
6  the extent permitted by applicable law. You can redistribute it
7  and/or modify it under the terms of the Do What The Fuck You Want
8  To Public License, Version 2, as published by Sam Hocevar. See
9  http://sam.zoy.org/wtfpl/COPYING for more details.
11 Package [ System ]
14 File extend [
15 readDWord [
16   | res shift |
17   res := shift := 0.
18   1 to: 4 do: [:c |
19     (c := self readCharValue) ifNil: [ self error: 'unexpeced end of file' ].
20     c := c bitShift: shift.
21     res := res bitOr: c.
22     shift := shift + 8.
23   ].
24   ^res
27 writeDWord: dw [
28   | shift |
29   shift := 0.
30   1 to: 4 do: [:c |
31     c := (dw bitShift: 0 - shift) bitAnd: 255.
32     self writeCharValue: c.
33     shift := shift + 8.
34   ].
37 copyFrom: fsrc size: count [
38   | buf rd |
39   buf := ByteArray new: 65536.
40   [ count > 0 ] whileTrue: [
41     rd := count min: buf size.
42     rd := (fsrc read: buf size: rd).
43     rd <= 0 ifTrue: [ self error: 'file reading error' ].
44     (self write: buf size: rd) = rd ifFalse: [ self error: 'file writing error' ].
45     count := count - rd. ].