Skip to content

Commit

Permalink
Merge pull request #15 from lpil/upgrade
Browse files Browse the repository at this point in the history
Update for Gleam v0.32
  • Loading branch information
bcpeinhardt authored Nov 6, 2023
2 parents ecd0343 + 8308c9f commit 166748f
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 98 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.5.1
- uses: erlef/setup-beam@v1.15.4
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: "25.2"
gleam-version: "0.30.5"
gleam-version: "0.32.2"
rebar3-version: "3"
# elixir-version: "1.14.2"
- run: gleam format --check src test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.ez
build
erl_crash.dump
tmp
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
- Updated for Gleam v0.32.

## v0.1.14 - 18 September 2023
- added `delete_all` which takes a list of paths to call delete on
Expand Down
6 changes: 2 additions & 4 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ name = "simplifile"
version = "0.1.14"
description = "Basic file operations that work on all targets"

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

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

[dev-dependencies]
gleeunit = "~> 0.10"
gleeunit = "~> 1.0"
6 changes: 3 additions & 3 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# You typically do not need to edit this file

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

[requirements]
gleam_stdlib = { version = "~> 0.29" }
gleeunit = { version = "~> 0.10" }
gleeunit = { version = "~> 1.0" }
42 changes: 18 additions & 24 deletions src/simplifile.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gleam/bit_string
import gleam/bit_array
import gleam/string
import gleam/result
import gleam/list
Expand Down Expand Up @@ -181,7 +181,7 @@ pub fn append(contents: String, to filepath: String) -> Result(Nil, FileError) {
/// let assert Ok(records) = read_bits(from: "./users.csv")
/// ```
///
pub fn read_bits(from filepath: String) -> Result(BitString, FileError) {
pub fn read_bits(from filepath: String) -> Result(BitArray, FileError) {
do_read_bits(filepath)
|> cast_error
}
Expand All @@ -192,10 +192,7 @@ pub fn read_bits(from filepath: String) -> Result(BitString, FileError) {
/// let assert Ok(Nil) = write_bits(<<"Hello, World!":utf8>>, to: "./hello_world.txt")
/// ```
///
pub fn write_bits(
bits: BitString,
to filepath: String,
) -> Result(Nil, FileError) {
pub fn write_bits(bits: BitArray, to filepath: String) -> Result(Nil, FileError) {
do_write_bits(bits, filepath)
|> cast_error
}
Expand All @@ -207,7 +204,7 @@ pub fn write_bits(
/// ```
///
pub fn append_bits(
bits: BitString,
bits: BitArray,
to filepath: String,
) -> Result(Nil, FileError) {
do_append_bits(bits, filepath)
Expand Down Expand Up @@ -351,8 +348,8 @@ pub fn rename_directory(
@target(javascript)
fn do_read(from filepath: String) -> Result(String, String) {
case do_read_bits(filepath) {
Ok(bit_str) -> {
case bit_string.to_string(bit_str) {
Ok(bits) -> {
case bit_array.to_string(bits) {
Ok(str) -> Ok(str)
_ -> Error("NOTUTF8")
}
Expand All @@ -364,7 +361,7 @@ fn do_read(from filepath: String) -> Result(String, String) {
@target(javascript)
fn do_write(content: String, to filepath: String) -> Result(Nil, String) {
content
|> bit_string.from_string
|> bit_array.from_string
|> do_write_bits(to: filepath)
}

Expand All @@ -375,24 +372,21 @@ fn do_delete(file_or_dir_at: String) -> Result(Nil, String)
@target(javascript)
fn do_append(content: String, to filepath: String) -> Result(Nil, String) {
content
|> bit_string.from_string
|> bit_array.from_string
|> do_append_bits(to: filepath)
}

@target(javascript)
@external(javascript, "./simplifile_js.mjs", "readBits")
fn do_read_bits(from: String) -> Result(BitString, String)
fn do_read_bits(from: String) -> Result(BitArray, String)

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

@target(javascript)
@external(javascript, "./simplifile_js.mjs", "appendBits")
fn do_append_bits(
content: BitString,
to filepath: String,
) -> Result(Nil, String)
fn do_append_bits(content: BitArray, to filepath: String) -> Result(Nil, String)

@target(javascript)
@external(javascript, "./simplifile_js.mjs", "isDirectory")
Expand Down Expand Up @@ -481,20 +475,20 @@ fn cast_error(input: Result(a, String)) -> Result(a, FileError) {
@target(erlang)
@external(erlang, "simplifile_erl", "append_file")
fn do_append_bits(
content: BitString,
content: BitArray,
to filepath: String,
) -> Result(Nil, FileError)

@target(erlang)
@external(erlang, "simplifile_erl", "write_file")
fn do_write_bits(
content: BitString,
content: BitArray,
to filepath: String,
) -> Result(Nil, FileError)

@target(erlang)
@external(erlang, "simplifile_erl", "read_file")
fn do_read_bits(from: String) -> Result(BitString, FileError)
fn do_read_bits(from: String) -> Result(BitArray, FileError)

@target(erlang)
@external(erlang, "simplifile_erl", "recursive_delete")
Expand All @@ -503,22 +497,22 @@ fn do_delete(file_or_dir_at: String) -> Result(Nil, FileError)
@target(erlang)
fn do_append(content: String, to filepath: String) -> Result(Nil, FileError) {
content
|> bit_string.from_string
|> bit_array.from_string
|> do_append_bits(filepath)
}

@target(erlang)
fn do_write(content: String, to filepath: String) -> Result(Nil, FileError) {
content
|> bit_string.from_string
|> bit_array.from_string
|> do_write_bits(filepath)
}

@target(erlang)
fn do_read(from filepath: String) -> Result(String, FileError) {
case do_read_bits(filepath) {
Ok(bit_str) -> {
case bit_string.to_string(bit_str) {
Ok(bits) -> {
case bit_array.to_string(bits) {
Ok(str) -> Ok(str)
_ -> Error(NotUtf8)
}
Expand Down
Loading

0 comments on commit 166748f

Please sign in to comment.