From: keyboard on
Hi, all:

I have a very simple program, but comes out with error like:

READ-CHAR-SEQUENCE: Invalid byte sequence #xDF #x32 in CHARSET:UTF-8
conversion
[Condition of type SIMPLE-CHARSET-TYPE-ERROR]

[code
(defun read-persistence (in-file &optional (out-file "out") (start
#x3000) (end #x3f00))
(let*
((size (- end start))
(data (make-array size :initial-element nil)))
(with-open-file (if in-file)
(read-sequence data if :start start :end end))
(with-open-file (of out-file :direction :output)
(write-sequence data of)))
)
code]

What does this mean? My in-file is a normal binary file.
From: Rainer Joswig on
In article
<6d2b1197-3128-44ab-9880-f4a22f3f0189(a)z7g2000yqb.googlegroups.com>,
keyboard <xiewensheng(a)gmail.com> wrote:

> Hi, all:
>
> I have a very simple program, but comes out with error like:
>
> READ-CHAR-SEQUENCE: Invalid byte sequence #xDF #x32 in CHARSET:UTF-8
> conversion
> [Condition of type SIMPLE-CHARSET-TYPE-ERROR]
>
> [code
> (defun read-persistence (in-file &optional (out-file "out") (start
> #x3000) (end #x3f00))
> (let*
> ((size (- end start))
> (data (make-array size :initial-element nil)))
> (with-open-file (if in-file)
> (read-sequence data if :start start :end end))
> (with-open-file (of out-file :direction :output)
> (write-sequence data of)))
> )
> code]
>
> What does this mean? My in-file is a normal binary file.

You might want to open the file(s) as binary then.

--
http://lispm.dyndns.org/
From: vanekl on
keyboard wrote:
> Hi, all:
>
> I have a very simple program, but comes out with error like:
>
> READ-CHAR-SEQUENCE: Invalid byte sequence #xDF #x32 in CHARSET:UTF-8
> conversion
> [Condition of type SIMPLE-CHARSET-TYPE-ERROR]
>
> [code
> (defun read-persistence (in-file &optional (out-file "out") (start
> #x3000) (end #x3f00))
> (let*
> ((size (- end start))
> (data (make-array size :initial-element nil)))
> (with-open-file (if in-file)
> (read-sequence data if :start start :end end))
> (with-open-file (of out-file :direction :output)
> (write-sequence data of)))
> )
> code]
>
> What does this mean? My in-file is a normal binary file.

When you opened the file, the default file encoding was UTF-8. UTF-8 has a
specific binary representation when encoding characters. #xDF #x32 does not
represent any UTF-8 character/code point. It's invalid, so CL didn't know
what to do except throw an error.

If you want to open a "normal" binary file, try changing the encoding.

(deftype octet () '(unsigned-byte 8))

(defun read-persistence (in-file-path &optional
(start #x3000) (end #x3f00))
(let ((data (make-array end :initial-element nil)))
(with-open-file (in-stm in-file-path :direction :input :element-type
'octet)
(read-sequence data in-stm :start start :end end))
data))


From: keyboard on
Thanks.

The problem is now solved.

Is there a way to read out only one (middle) part of a file ? - the
file is really big and using a big-sized array is not so economic, and
using loop is not handy because the file size is changing.

regards,
From: Rainer Joswig on
In article
<33ef09d2-2291-43b4-9929-d649ebddc740(a)g11g2000yqe.googlegroups.com>,
keyboard <xiewensheng(a)gmail.com> wrote:

> Thanks.
>
> The problem is now solved.
>
> Is there a way to read out only one (middle) part of a file ? - the
> file is really big and using a big-sized array is not so economic, and
> using loop is not handy because the file size is changing.

See the function FILE-POSITION .

>
> regards,

--
http://lispm.dyndns.org/
 | 
Pages: 1
Prev: keywords & macros
Next: Accepting online payment