Skip to content

Commit 8308c9f

Browse files
committedNov 6, 2023
Update for Gleam v0.32
I've also made the tmp files be written to a git ignored `tmp` rather than into the src tree as a crash half way through the tests left me with various test files to delete before I could run the tests again. I hope that's ok!
1 parent ecd0343 commit 8308c9f

File tree

7 files changed

+92
-98
lines changed

7 files changed

+92
-98
lines changed
 

‎.github/workflows/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ jobs:
1111
test:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3.5.1
15-
- uses: erlef/setup-beam@v1.15.4
14+
- uses: actions/checkout@v3
15+
- uses: erlef/setup-beam@v1
1616
with:
1717
otp-version: "25.2"
18-
gleam-version: "0.30.5"
18+
gleam-version: "0.32.2"
1919
rebar3-version: "3"
2020
# elixir-version: "1.14.2"
2121
- run: gleam format --check src test

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.ez
33
build
44
erl_crash.dump
5+
tmp

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
- Updated for Gleam v0.32.
45

56
## v0.1.14 - 18 September 2023
67
- added `delete_all` which takes a list of paths to call delete on

‎gleam.toml

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ name = "simplifile"
22
version = "0.1.14"
33
description = "Basic file operations that work on all targets"
44

5-
# Fill out these fields if you intend to generate HTML documentation or publish
6-
# your project to the Hex package manager.
7-
#
85
licences = ["Apache-2.0"]
96
repository = { type = "github", user = "bcpeinhardt", repo = "simplifile" }
7+
gleam = ">= 0.32.2"
108
# links = [{ title = "Website", href = "https://gleam.run" }]
119

1210
[javascript.deno]
@@ -16,4 +14,4 @@ allow_all = true
1614
gleam_stdlib = "~> 0.29"
1715

1816
[dev-dependencies]
19-
gleeunit = "~> 0.10"
17+
gleeunit = "~> 1.0"

‎manifest.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# You typically do not need to edit this file
33

44
packages = [
5-
{ name = "gleam_stdlib", version = "0.30.2", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "8D8BF3790AA31176B1E1C0B517DD74C86DA8235CF3389EA02043EE4FD82AE3DC" },
6-
{ name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" },
5+
{ name = "gleam_stdlib", version = "0.32.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "07D64C26D014CF570F8ACADCE602761EA2E74C842D26F2FD49B0D61973D9966F" },
6+
{ name = "gleeunit", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D3682ED8C5F9CAE1C928F2506DE91625588CC752495988CBE0F5653A42A6F334" },
77
]
88

99
[requirements]
1010
gleam_stdlib = { version = "~> 0.29" }
11-
gleeunit = { version = "~> 0.10" }
11+
gleeunit = { version = "~> 1.0" }

‎src/simplifile.gleam

+18-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import gleam/bit_string
1+
import gleam/bit_array
22
import gleam/string
33
import gleam/result
44
import gleam/list
@@ -181,7 +181,7 @@ pub fn append(contents: String, to filepath: String) -> Result(Nil, FileError) {
181181
/// let assert Ok(records) = read_bits(from: "./users.csv")
182182
/// ```
183183
///
184-
pub fn read_bits(from filepath: String) -> Result(BitString, FileError) {
184+
pub fn read_bits(from filepath: String) -> Result(BitArray, FileError) {
185185
do_read_bits(filepath)
186186
|> cast_error
187187
}
@@ -192,10 +192,7 @@ pub fn read_bits(from filepath: String) -> Result(BitString, FileError) {
192192
/// let assert Ok(Nil) = write_bits(<<"Hello, World!":utf8>>, to: "./hello_world.txt")
193193
/// ```
194194
///
195-
pub fn write_bits(
196-
bits: BitString,
197-
to filepath: String,
198-
) -> Result(Nil, FileError) {
195+
pub fn write_bits(bits: BitArray, to filepath: String) -> Result(Nil, FileError) {
199196
do_write_bits(bits, filepath)
200197
|> cast_error
201198
}
@@ -207,7 +204,7 @@ pub fn write_bits(
207204
/// ```
208205
///
209206
pub fn append_bits(
210-
bits: BitString,
207+
bits: BitArray,
211208
to filepath: String,
212209
) -> Result(Nil, FileError) {
213210
do_append_bits(bits, filepath)
@@ -351,8 +348,8 @@ pub fn rename_directory(
351348
@target(javascript)
352349
fn do_read(from filepath: String) -> Result(String, String) {
353350
case do_read_bits(filepath) {
354-
Ok(bit_str) -> {
355-
case bit_string.to_string(bit_str) {
351+
Ok(bits) -> {
352+
case bit_array.to_string(bits) {
356353
Ok(str) -> Ok(str)
357354
_ -> Error("NOTUTF8")
358355
}
@@ -364,7 +361,7 @@ fn do_read(from filepath: String) -> Result(String, String) {
364361
@target(javascript)
365362
fn do_write(content: String, to filepath: String) -> Result(Nil, String) {
366363
content
367-
|> bit_string.from_string
364+
|> bit_array.from_string
368365
|> do_write_bits(to: filepath)
369366
}
370367

@@ -375,24 +372,21 @@ fn do_delete(file_or_dir_at: String) -> Result(Nil, String)
375372
@target(javascript)
376373
fn do_append(content: String, to filepath: String) -> Result(Nil, String) {
377374
content
378-
|> bit_string.from_string
375+
|> bit_array.from_string
379376
|> do_append_bits(to: filepath)
380377
}
381378

382379
@target(javascript)
383380
@external(javascript, "./simplifile_js.mjs", "readBits")
384-
fn do_read_bits(from: String) -> Result(BitString, String)
381+
fn do_read_bits(from: String) -> Result(BitArray, String)
385382

386383
@target(javascript)
387384
@external(javascript, "./simplifile_js.mjs", "writeBits")
388-
fn do_write_bits(content: BitString, to filepath: String) -> Result(Nil, String)
385+
fn do_write_bits(content: BitArray, to filepath: String) -> Result(Nil, String)
389386

390387
@target(javascript)
391388
@external(javascript, "./simplifile_js.mjs", "appendBits")
392-
fn do_append_bits(
393-
content: BitString,
394-
to filepath: String,
395-
) -> Result(Nil, String)
389+
fn do_append_bits(content: BitArray, to filepath: String) -> Result(Nil, String)
396390

397391
@target(javascript)
398392
@external(javascript, "./simplifile_js.mjs", "isDirectory")
@@ -481,20 +475,20 @@ fn cast_error(input: Result(a, String)) -> Result(a, FileError) {
481475
@target(erlang)
482476
@external(erlang, "simplifile_erl", "append_file")
483477
fn do_append_bits(
484-
content: BitString,
478+
content: BitArray,
485479
to filepath: String,
486480
) -> Result(Nil, FileError)
487481

488482
@target(erlang)
489483
@external(erlang, "simplifile_erl", "write_file")
490484
fn do_write_bits(
491-
content: BitString,
485+
content: BitArray,
492486
to filepath: String,
493487
) -> Result(Nil, FileError)
494488

495489
@target(erlang)
496490
@external(erlang, "simplifile_erl", "read_file")
497-
fn do_read_bits(from: String) -> Result(BitString, FileError)
491+
fn do_read_bits(from: String) -> Result(BitArray, FileError)
498492

499493
@target(erlang)
500494
@external(erlang, "simplifile_erl", "recursive_delete")
@@ -503,22 +497,22 @@ fn do_delete(file_or_dir_at: String) -> Result(Nil, FileError)
503497
@target(erlang)
504498
fn do_append(content: String, to filepath: String) -> Result(Nil, FileError) {
505499
content
506-
|> bit_string.from_string
500+
|> bit_array.from_string
507501
|> do_append_bits(filepath)
508502
}
509503

510504
@target(erlang)
511505
fn do_write(content: String, to filepath: String) -> Result(Nil, FileError) {
512506
content
513-
|> bit_string.from_string
507+
|> bit_array.from_string
514508
|> do_write_bits(filepath)
515509
}
516510

517511
@target(erlang)
518512
fn do_read(from filepath: String) -> Result(String, FileError) {
519513
case do_read_bits(filepath) {
520-
Ok(bit_str) -> {
521-
case bit_string.to_string(bit_str) {
514+
Ok(bits) -> {
515+
case bit_array.to_string(bits) {
522516
Ok(str) -> Ok(str)
523517
_ -> Error(NotUtf8)
524518
}

0 commit comments

Comments
 (0)
Please sign in to comment.