File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -61,13 +61,16 @@ decode: function [
61
61
encode : function [
62
62
{Encodes a datatype (e.g. image!) into a series of bytes.}
63
63
type [word! ] {Media type (jpeg, png, etc.)}
64
- data [ image! binary! string! ] {The data to encode}
64
+ data {The data to encode}
65
65
/options opts [block! ] {Special encoding options}
66
66
] [
67
67
unless all [
68
68
cod: select system/codecs type
69
69
data: either handle? try [cod/entry ] [
70
70
; original codecs were only natives
71
+ if type = 'text [
72
+ return either binary? data [to string! data][form data]
73
+ ]
71
74
do-codec cod/entry 'encode data
72
75
][
73
76
either function? try [: cod/encode ][
Original file line number Diff line number Diff line change @@ -14,6 +14,33 @@ Rebol [
14
14
--assert 'text = encoding? #{ 6162 }
15
15
===end-group===
16
16
17
+ ===start-group=== "TEXT codec"
18
+ --test-- "ENCODE text"
19
+ --assert "1 2" = encode 'text [1 2 ]
20
+ --assert "1 2" = encode 'text #{ 312032 }
21
+ --test-- "SAVE %test.txt"
22
+ --assert [1 2 ] = load save %temp.bin [1 2 ]
23
+ --assert "1 2" = load save %temp.txt [1 2 ] ;-- note that result is STRING
24
+ --assert "#{312032}^/ " = read /string %temp.bin ;@@ should be there the newline char?!
25
+ --assert "1 2" = read /string %temp.txt
26
+ delete %temp.bin
27
+ delete %temp.txt
28
+
29
+ ===end-group===
30
+
31
+ ===start-group=== "Invalid SAVE"
32
+ --test-- "invalid image SAVE"
33
+ --assert error? try [save %temp.bmp [1 2 ]]
34
+ --assert error? try [save %temp.png [1 2 ]]
35
+ --assert error? try [save %temp.jpg [1 2 ]]
36
+ --assert error? try [save %temp.bmp "foo" ]
37
+ --assert error? try [save %temp.png "foo" ]
38
+ --assert error? try [save %temp.jpg "foo" ]
39
+ --assert error? try [save %temp.bmp #{ 00 } ]
40
+ --assert error? try [save %temp.png #{ 00 } ]
41
+ --assert error? try [save %temp.jpg #{ 00 } ]
42
+
43
+
17
44
if find system/codecs 'wav [
18
45
system/codecs/wav/verbose: 3
19
46
===start-group=== "WAV codec"
You can’t perform that action at this time.
0 commit comments