File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
27
27
* Fixed issue with import modules aliasing using ns eval (#719 )
28
28
* Fix issue with ` ns-resolve ` throwing an error on macros (#720 )
29
29
* Fix issue with py module ` readerwritelock ` locks handling (#722 )
30
+ * Fix issue with basilisp.io/writer : append mode not working (#741 ).
30
31
31
32
### Removed
32
33
* Removed the dependency ` astor ` for versions of Python 3.9+ (#736 )
Original file line number Diff line number Diff line change 80
80
81
81
(defn- clean-writer-mode
82
82
[opts]
83
- (let [mode (:mode opts "w")
83
+ (let [append? (:append opts)
84
+ mode (:mode opts "")
84
85
clean-mode (cond
85
86
(:append opts) (str "a" mode)
86
87
(not (str/includes? mode "w")) (str "w" mode)
96
97
(ex-info "Writers may only be open in write or append mode"
97
98
{:mode mode})))
98
99
99
- (assoc opts :mode clean-mode)))
100
+ (-> (assoc opts :mode clean-mode)
101
+ (dissoc :append))))
100
102
101
103
(defn- clean-binary-mode
102
104
[opts]
325
327
The writer instances returned are always text-based, not binary. In general, the
326
328
writers should be compatible with Python's ``io.TextIOBase`` interface.
327
329
330
+ ``opts`` is an optional collection of keyword/value pairs
331
+ transmitted as a map to the writer. The acceptable keywords align
332
+ with those recognized by the fn:``open`` function. Moreover, setting the
333
+ :append option to true will configure the writer for append mode.
334
+
328
335
Callers should take care to open a writer instance using
329
336
:lpy:fn:`basilisp.core/with-open` to ensure that any resources are properly closed
330
337
afterwards. Note that for in-memory IO buffers such as ``io.BytesIO`` and
Original file line number Diff line number Diff line change 175
175
(os/close fd)
176
176
(os/unlink filename)))))))
177
177
178
+ (testing "writer local files"
179
+ (let [path (bio/path *tempdir* "writer-test-writer-local-files.txt")]
180
+ (testing "writer file object write"
181
+ (with-open [f (bio/writer path)]
182
+ (.write f "some file contents"))
183
+ (is (= "some file contents" (slurp path))))
184
+
185
+ (testing "writer file object append"
186
+ (with-open [f (bio/writer path :append true)]
187
+ (.write f " and then some more"))
188
+ (is (= "some file contents and then some more" (slurp path)))
189
+
190
+ (with-open [f (bio/writer path :append false)]
191
+ (.write f "some other content"))
192
+ (is (= "some other content" (slurp path))))))
193
+
178
194
(testing "http requests"
179
195
(let [url (str "http://localhost:" *http-port* "/writer-http-req.txt")]
180
196
(is (thrown? basilisp.lang.exception/ExceptionInfo
You can’t perform that action at this time.
0 commit comments