Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-snezhko committed Mar 2, 2024
1 parent abc6b71 commit 2973bba
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module FsTest

from "sys/fs" include Fs
from "fs" include Fs
from "path" include Path
from "bytes" include Bytes
from "result" include Result
Expand Down
22 changes: 18 additions & 4 deletions stdlib/sys/fs.gr → stdlib/fs.gr
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
/**
* High-level file system interactions. Utilizes WASI Preview 1 for underlying API
*
* @example from "fs" include Fs
*
* @since v0.6.0
*/
module Fs

from "sys/file" include File
from "bytes" include Bytes
from "array" include Array
from "bytes" include Bytes
from "int64" include Int64
from "option" include Option
from "result" include Result
from "path" include Path
from "int64" include Int64
from "result" include Result
from "string" include String
from "sys/file" include File
from "runtime/wasi" include Wasi
from "runtime/unsafe/wasmi32" include WasmI32
from "runtime/dataStructures" include DataStructures
Expand Down Expand Up @@ -194,12 +201,19 @@ provide enum FileType {
*/
provide record Stats {
fileType: FileType,
/** File size in bytes */
size: Number,
/** Last accessed timestamp in nanoseconds */
accessedTimestamp: Number,
/** Last modified timestamp in nanoseconds */
modifiedTimestamp: Number,
/** Last file status change timestamp in nanoseconds */
changedTimestamp: Number,
}

/**
* Represents information about an item in a directory
*/
provide record DirectoryEntry {
name: String,
fileType: FileType,
Expand Down
23 changes: 23 additions & 0 deletions stdlib/sys/fs.md → stdlib/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
title: Fs
---

High-level file system interactions. Utilizes WASI Preview 1 for underlying API

<details disabled>
<summary tabindex="-1">Added in <code>next</code></summary>
No other changes yet.
</details>

```grain
from "fs" include Fs
```

## Types

Type declarations included in the Fs module.
Expand Down Expand Up @@ -129,6 +140,16 @@ record Stats {

Represents metadata about a file.

Fields:

|name|type|description|
|----|----|-----------|
|`fileType`|`FileType`||
|`size`|`Number`|File size in bytes|
|`accessedTimestamp`|`Number`|Last accessed timestamp in nanoseconds|
|`modifiedTimestamp`|`Number`|Last modified timestamp in nanoseconds|
|`changedTimestamp`|`Number`|Last file status change timestamp in nanoseconds|

### Fs.**DirectoryEntry**

```grain
Expand All @@ -138,6 +159,8 @@ record DirectoryEntry {
}
```

Represents information about an item in a directory

### Fs.**RemoveMode**

```grain
Expand Down
2 changes: 1 addition & 1 deletion stdlib/path.gr
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ provide let relativeTo = (source, dest) => {
let pathInfo2 = pathInfo(dest)
let (base2, _, _) = pathInfo2
match ((base1, base2)) {
(Abs(_), Rel(_)) | (Rel(_), Abs(_)) => Err(Incompatible(DifferentBases)),
(Abs(_), Rel(_)) | (Abs(_), Rel(_)) => Err(Incompatible(DifferentBases)),
_ => Result.map(toPath, relativeToHelper(pathInfo1, pathInfo2)),
}
}
Expand Down

0 comments on commit 2973bba

Please sign in to comment.