Skip to content

Commit efcf890

Browse files
committed
api returns: gunzip now returns extracted file
Step 3e for #197 (comment) Tests updated appropriately. Also: moved "Returns.." above Options for `gzip` for consistency.
1 parent 9123182 commit efcf890

4 files changed

Lines changed: 36 additions & 30 deletions

File tree

API.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ See also: [`set-creation-time`](#babashka.fs/set-creation-time), [`last-modified
342342
Function.
343343

344344
Returns current working directory path.
345-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1511-L1514">Source</a></sub></p>
345+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1514-L1517">Source</a></sub></p>
346346

347347
## <a name="babashka.fs/delete">`delete`</a>
348348
``` clojure
@@ -464,7 +464,7 @@ assumed to be a username, then naively expanded to `(home username)`.
464464
e.g., `~someuser/foo` -> `/home/someuser/foo`
465465

466466
See also: [`home`](#babashka.fs/home)
467-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1484-L1504">Source</a></sub></p>
467+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1487-L1507">Source</a></sub></p>
468468

469469
## <a name="babashka.fs/extension">`extension`</a>
470470
``` clojure
@@ -590,11 +590,13 @@ File is extracted to `target-dir` with `gz-file` [`file-name`](#babashka.fs/file
590590
Creates `target-dir` dir(s) if necessary.
591591
The `gz-file` is not deleted.
592592

593+
Returns the extracted file.
594+
593595
Options:
594596
* `:replace-existing` - when `true` overwrites existing file
595597

596598
See also: [`gzip`](#babashka.fs/gzip)
597-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1372-L1401">Source</a></sub></p>
599+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1372-L1404">Source</a></sub></p>
598600

599601
## <a name="babashka.fs/gzip">`gzip`</a>
600602
``` clojure
@@ -608,14 +610,14 @@ Gzips `source-file` to `:dir`/`:out-file`.
608610
Does not store the `source-file` name in the `.gz` file.
609611
The `source-file` is not deleted.
610612

613+
Returns the created gzip file.
614+
611615
Options:
612616
* `:dir`(s) - created if necessary. If not specified, defaults to `source-file` dir.
613617
* `:out-file` - if not specified, defaults to `source-file` [`file-name`](#babashka.fs/file-name) with `.gz` extension.
614618

615-
Returns the created gzip file.
616-
617619
See also: [`gunzip`](#babashka.fs/gunzip)
618-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1403-L1433">Source</a></sub></p>
620+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1406-L1436">Source</a></sub></p>
619621

620622
## <a name="babashka.fs/hidden?">`hidden?`</a>
621623
``` clojure
@@ -641,7 +643,7 @@ Returns home dir path.
641643
With no arguments, returns the current value of the `user.home`
642644
system property. If a `user` is passed, returns that user's home
643645
directory as found in the parent of home with no args.
644-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1474-L1482">Source</a></sub></p>
646+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1477-L1485">Source</a></sub></p>
645647

646648
## <a name="babashka.fs/instant->file-time">`instant->file-time`</a>
647649
``` clojure
@@ -1153,7 +1155,7 @@ or [FileTime](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/
11531155
Function.
11541156

11551157
Returns `path` as string with Unix-style file separators (`/`).
1156-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1603-L1609">Source</a></sub></p>
1158+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1606-L1612">Source</a></sub></p>
11571159

11581160
## <a name="babashka.fs/unzip">`unzip`</a>
11591161
``` clojure
@@ -1190,7 +1192,7 @@ Returns the new contents.
11901192

11911193
Options:
11921194
* `:charset` - charset of file, default to "utf-8"
1193-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1584-L1601">Source</a></sub></p>
1195+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1587-L1604">Source</a></sub></p>
11941196

11951197
## <a name="babashka.fs/walk-file-tree">`walk-file-tree`</a>
11961198
``` clojure
@@ -1253,7 +1255,7 @@ Returns a vector of every path to `program` found in ([`exec-paths`](#babashka.f
12531255
Function.
12541256

12551257
Returns `true` if OS is Windows.
1256-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1506-L1509">Source</a></sub></p>
1258+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1509-L1512">Source</a></sub></p>
12571259

12581260
## <a name="babashka.fs/with-temp-dir">`with-temp-dir`</a>
12591261
``` clojure
@@ -1280,7 +1282,7 @@ Example:
12801282
;; d no longer exists here
12811283
```
12821284

1283-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1437-L1466">Source</a></sub></p>
1285+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1440-L1469">Source</a></sub></p>
12841286

12851287
## <a name="babashka.fs/writable?">`writable?`</a>
12861288
``` clojure
@@ -1313,7 +1315,7 @@ Examples:
13131315
(fs/write-bytes f (.getBytes (String. "foo"))) ;; overwrites + truncates or creates new file
13141316
(fs/write-bytes f (.getBytes (String. "foo")) {:append true})
13151317
```
1316-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1537-L1561">Source</a></sub></p>
1318+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1540-L1564">Source</a></sub></p>
13171319

13181320
## <a name="babashka.fs/write-lines">`write-lines`</a>
13191321
``` clojure
@@ -1333,7 +1335,7 @@ Open options:
13331335
* `:write` - (default `true`)
13341336
* `:append` - (default `false`)
13351337
* or any `java.nio.file.StandardOption`.
1336-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1563-L1582">Source</a></sub></p>
1338+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1566-L1585">Source</a></sub></p>
13371339

13381340
## <a name="babashka.fs/xdg-cache-home">`xdg-cache-home`</a>
13391341
``` clojure
@@ -1346,7 +1348,7 @@ Returns path to user-specific non-essential data as described in the [XDG Base D
13461348

13471349
Uses env-var `XDG_CACHE_HOME` (if set and representing an absolute path), else `(fs/path (fs/home) ".cache")`.
13481350
When provided, appends `app` to the returned path.
1349-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1641-L1649">Source</a></sub></p>
1351+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1644-L1652">Source</a></sub></p>
13501352

13511353
## <a name="babashka.fs/xdg-config-home">`xdg-config-home`</a>
13521354
``` clojure
@@ -1359,7 +1361,7 @@ Returns path to user-specific configuration files as described in the [XDG Base
13591361

13601362
Uses env-var `XDG_CONFIG_HOME` (if set and representing an absolute path), else `(fs/path (fs/home) ".config")`.
13611363
When provided, appends `app` to the returned path.
1362-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1631-L1639">Source</a></sub></p>
1364+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1634-L1642">Source</a></sub></p>
13631365

13641366
## <a name="babashka.fs/xdg-data-home">`xdg-data-home`</a>
13651367
``` clojure
@@ -1372,7 +1374,7 @@ Returns path to user-specific data files as described in the [XDG Base Directory
13721374

13731375
Uses env-var `XDG_DATA_HOME` (if set and representing an absolute path), else `(fs/path (fs/home) ".local" "share")`.
13741376
When provided, appends `app` to the returned path.
1375-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1651-L1659">Source</a></sub></p>
1377+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1654-L1662">Source</a></sub></p>
13761378

13771379
## <a name="babashka.fs/xdg-state-home">`xdg-state-home`</a>
13781380
``` clojure
@@ -1385,7 +1387,7 @@ Returns path to user-specific state files as described in the [XDG Base Director
13851387

13861388
Uses env-var `XDG_STATE_HOME` (if set and representing an absolute path), else `(fs/path (fs/home) ".local" "state")`.
13871389
When provided, appends `app` to the returned path.
1388-
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1661-L1669">Source</a></sub></p>
1390+
<p><sub><a href="https://github.com/babashka/fs/blob/master/src/babashka/fs.cljc#L1664-L1672">Source</a></sub></p>
13891391

13901392
## <a name="babashka.fs/zip">`zip`</a>
13911393
``` clojure

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Babashka [fs](https://github.com/babashka/fs): file system utility library for C
1111
- `copy` returns copied target file (fixed for case when `source` is input stream)
1212
- `copy-tree` now explicitly returns `target-dir` (previously undefined)
1313
- `delete-tree` existing return value now documented (previously undefined)
14+
- `gunzip` now explicitly returns the extracted file (previously undefined)
1415
- `unzip` now explicitly returns `target-dir` (previously undefined)
1516
- `zip` now explicitly returns created `zip-file` (previously undefined)
1617

src/babashka/fs.cljc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,8 @@
13791379
Creates `target-dir` dir(s) if necessary.
13801380
The `gz-file` is not deleted.
13811381
1382+
Returns the extracted file.
1383+
13821384
Options:
13831385
* `:replace-existing` - when `true` overwrites existing file
13841386
@@ -1398,20 +1400,21 @@
13981400
(create-dirs (parent output-file)))
13991401
(Files/copy ^java.io.InputStream gzis
14001402
output-file
1401-
cp-opts)))))
1403+
cp-opts))
1404+
output-file)))
14021405

14031406
(defn gzip
14041407
"Gzips `source-file` to `:dir`/`:out-file`.
14051408
14061409
Does not store the `source-file` name in the `.gz` file.
14071410
The `source-file` is not deleted.
14081411
1412+
Returns the created gzip file.
1413+
14091414
Options:
14101415
* `:dir`(s) - created if necessary. If not specified, defaults to `source-file` dir.
14111416
* `:out-file` - if not specified, defaults to `source-file` [[file-name]] with `.gz` extension.
14121417
1413-
Returns the created gzip file.
1414-
14151418
See also: [[gunzip]]"
14161419
([source-file]
14171420
(gzip source-file {}))

test/babashka/fs_test.clj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@
985985
(fs/gunzip expected-gz-file))
986986
"throws on attempted overwrite")
987987
;; NOTE: we must specify the `dest` when specifying options, specify `nil` for default
988-
(fs/gunzip expected-gz-file nil {:replace-existing true})
988+
(is (= input-file (str (fs/gunzip expected-gz-file nil {:replace-existing true}))))
989989
(is (match? (normalized
990990
[input-file
991991
expected-gz-file]
@@ -1016,9 +1016,8 @@
10161016
"both input file and output file exist")
10171017
(if-not (= (fs/absolutize expected-ungz-file) (fs/absolutize input-file))
10181018
(do
1019-
(is (do (fs/gunzip expected-gz-file out-dir)
1020-
true)
1021-
"does not throw")
1019+
(is (= (fs/unixify (fs/path out-dir "README.md"))
1020+
(fs/unixify (fs/gunzip expected-gz-file out-dir))))
10221021
(is (match? (normalized
10231022
[input-file
10241023
expected-gz-file
@@ -1031,8 +1030,8 @@
10311030
(fs/gunzip expected-gz-file out-dir))
10321031
"throws on attempted overwrite")
10331032
(spit expected-ungz-file "some\nnew\ncontent\n")
1034-
(is (do (fs/gunzip expected-gz-file out-dir {:replace-existing true})
1035-
true)
1033+
(is (= (fs/unixify (fs/path out-dir "README.md"))
1034+
(fs/unixify (fs/gunzip expected-gz-file out-dir {:replace-existing true})))
10361035
"does not throw on overwrite")
10371036
(is (match? (normalized
10381037
[expected-gz-file
@@ -1055,9 +1054,10 @@
10551054
(files source-file)
10561055
(spit source-file "orig content")
10571056
(is (= expected-gz (fs/unixify (fs/gzip source-file opts))))
1058-
(fs/gunzip expected-gz "verify")
1059-
(is (= "orig content" (slurp (fs/file "verify" (-> expected-gz fs/file-name fs/strip-ext))))
1060-
"ungzipped matches original"))))
1057+
(let [expected-ungz (fs/unixify (fs/file "verify" (-> expected-gz fs/file-name fs/strip-ext)))]
1058+
(is (= expected-ungz (fs/unixify (fs/gunzip expected-gz "verify"))))
1059+
(is (= "orig content" (slurp expected-ungz))
1060+
"ungzipped matches original")))))
10611061

10621062
(deftest gzip-arg-types-test
10631063
(files "foo.txt")
@@ -1078,7 +1078,7 @@
10781078
gzip (fs/gzip "f1.ext")]
10791079
(is (thrown? java.nio.file.FileAlreadyExistsException (fs/gunzip gzip "")))
10801080
(Thread/sleep 50)
1081-
(fs/gunzip gzip "" {:replace-existing true})
1081+
(is (= "f1.ext" (str (fs/gunzip gzip "" {:replace-existing true}))))
10821082
(is (not= last-modified (fs/last-modified-time "f1.ext")))
10831083
(is (= content (slurp "f1.ext")))))
10841084

0 commit comments

Comments
 (0)