Skip to content

Commit

Permalink
FIX: SAVE broken with .txt suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed May 29, 2019
1 parent 7b9e655 commit f444421
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/mezz/sys-codec.r
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ decode: function [
encode: function [
{Encodes a datatype (e.g. image!) into a series of bytes.}
type [word!] {Media type (jpeg, png, etc.)}
data [image! binary! string!] {The data to encode}
data {The data to encode}
/options opts [block!] {Special encoding options}
][
unless all [
cod: select system/codecs type
data: either handle? try [cod/entry] [
; original codecs were only natives
if type = 'text [
return either binary? data [to string! data][form data]
]
do-codec cod/entry 'encode data
][
either function? try [:cod/encode][
Expand Down
27 changes: 27 additions & 0 deletions src/tests/units/codecs-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@ Rebol [
--assert 'text = encoding? #{6162}
===end-group===

===start-group=== "TEXT codec"
--test-- "ENCODE text"
--assert "1 2" = encode 'text [1 2]
--assert "1 2" = encode 'text #{312032}
--test-- "SAVE %test.txt"
--assert [1 2] = load save %temp.bin [1 2]
--assert "1 2" = load save %temp.txt [1 2] ;-- note that result is STRING
--assert "#{312032}^/" = read/string %temp.bin ;@@ should be there the newline char?!
--assert "1 2" = read/string %temp.txt
delete %temp.bin
delete %temp.txt

===end-group===

===start-group=== "Invalid SAVE"
--test-- "invalid image SAVE"
--assert error? try [save %temp.bmp [1 2]]
--assert error? try [save %temp.png [1 2]]
--assert error? try [save %temp.jpg [1 2]]
--assert error? try [save %temp.bmp "foo"]
--assert error? try [save %temp.png "foo"]
--assert error? try [save %temp.jpg "foo"]
--assert error? try [save %temp.bmp #{00}]
--assert error? try [save %temp.png #{00}]
--assert error? try [save %temp.jpg #{00}]


if find system/codecs 'wav [
system/codecs/wav/verbose: 3
===start-group=== "WAV codec"
Expand Down

0 comments on commit f444421

Please sign in to comment.