anchor.diff:              (error "Expected 0x~x got 0x~x" (char-code char) byte)))
       (continue () t)))
   
  -(defun string-to-octets (string &optional (external-format +ascii+))
  +(defun string-to-octets (string &optional (external-format +utf-8+))
     (flex:string-to-octets string :external-format external-format))
   
   (defun octets-to-string (octets external-format)
     (flex:octets-to-string octets :external-format external-format))
   
  -(defgeneric encode (object stream-or-symbol)
  -  (:documentation "Encode object and write it to stream or, if
  -stream-or-symbol is a symbol, use an in-memory stream and return the
  -resulting sequence.  "))
  +(defgeneric encode (object stream &key external-format)
  +  (:documentation "Encode object and write it to stream or, if stream
  +is nil, use an in-memory stream and return the resulting sequence."))
   
  -(defmethod encode (object (external-format-keyword symbol))
  -  (let ((*external-format* (flex:make-external-format external-format-keyword)))
  -    (flex:with-output-to-sequence (stream)
  -      (encode object stream))))
  +(defmethod encode (object (stream stream) &key (external-format +utf-8+))
  +  (encode object (flex:make-flexi-stream stream :external-format external-format)))
   
  -(defmethod encode ((list list) (stream flexi-stream))
  +(defmethod encode (object (stream (eql nil)) &key (external-format +utf-8+))
  +  (flex:with-output-to-sequence (stream)
  +    (encode object (flex:make-flexi-stream stream :external-format external-format))))
  +
  +(defmethod encode ((list list) (stream flexi-stream) &key &allow-other-keys)
     (write-byte (char-code #\l) stream)
     (dolist (x list)
       (encode x stream))
     (write-byte (char-code #\e) stream))
   
  -(defmethod encode ((dictionary hash-table) (stream flexi-stream))
  +(defmethod encode ((dictionary hash-table) (stream flexi-stream) &key &allow-other-keys)
     (write-byte (char-code #\d) stream)
     (dolist (x (dictionary->alist dictionary))
       (destructuring-bind (k . v) x
  
positive.code:       (encode v stream)))
    (write-byte (char-code #\e) stream))
  
  (defmethod encode ((string string) (stream flexi-stream))
    (let ((octets (string-to-octets string (external-format stream))))
      (write-sequence (string-to-octets (format nil "~a:" (length octets))) stream)
      (write-sequence octets stream)))
  
  (defmethod encode ((integer integer) (stream flexi-stream))
    (write-sequence (string-to-octets (format nil "i~ae" integer)) stream))
  
  (defmethod encode ((sequence array) (stream flexi-stream))
    (write-sequence (string-to-octets (format nil "~a:" (length sequence))) stream)
    (write-sequence sequence stream))
  
  (defgeneric decode (stream)
    (:documentation "Decode a bencode object from stream.  If stream is a flexi-stream,
  its external-format will be used for decoding strings.  If stream is
  an ordinary stream, a flexi-stream with an external-format of :utf-8
  will be created and used."))
  
  (defmethod decode ((stream stream))
    (decode (flex:make-flexi-stream stream :external-format +utf-8+)))
  
  (defmethod decode ((stream flexi-stream))
    (let ((c (code-char (flex:peek-byte stream))))
      (ccase c
        (#\i (decode-integer stream))
  
negative.code: 
  (in-package #:com.schobadoo.bencode)
  
  (defparameter +utf-8+ (flex:make-external-format :utf-8))
  
  (define-condition unexpected-octet (error)
    ((expected-octet :initarg :expected-octet :reader expected-octet)
  