This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-18
Channels
- # announcements (1)
- # babashka (17)
- # beginners (26)
- # calva (7)
- # clj-kondo (57)
- # cljdoc (8)
- # clojure (6)
- # clojure-europe (26)
- # clojure-italy (1)
- # clojure-nl (1)
- # clojure-norway (52)
- # clojure-uk (4)
- # datahike (1)
- # emacs (16)
- # events (1)
- # hyperfiddle (24)
- # introduce-yourself (1)
- # jobs (8)
- # lsp (6)
- # malli (9)
- # membrane (38)
- # missionary (5)
- # polylith (26)
- # portal (4)
- # reitit (1)
- # releases (7)
- # remote-jobs (1)
I am dealing with text data encoded in Shift-JIS. The
functions, as well as slurp
, accept an opts map to specify e.g. :encoding
. How should I consistently provide text encoding across code? It seems the time at which to provide :encoding
can make or break application logic. Example in thread.
✅ 1
note the time at which :encoding
is provided
(with-open [file (io/reader (io/resource "sample.dat"))]
(let [text (slurp file :encoding "Shift-JIS")]
(first (str/split text #"<>" 5))))
;; => distorted text
(with-open [file (io/reader (io/resource "sample.dat") :encoding "Shift-JIS")]
(let [text (slurp file)]
(first (str/split text #"<>" 5))))
;; => desired output
contrary to expectations, setting :encoding
to slurp
does not work in this caseThe "reader" decodes. You must configure the first reader that touches the input-stream.
So if I am expecting to read data from a variety of sources (e.g. not just local files, but also URLs), I should ensure to set encoding when constructing a Reader?