-
Notifications
You must be signed in to change notification settings - Fork 271
/
Copy pathFileIO5-notarget-java-cs-js-go-py.dfy
50 lines (45 loc) · 2.12 KB
/
FileIO5-notarget-java-cs-js-go-py.dfy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*******************************************************************************
* Copyright by the contributors to the Dafny Project
* SPDX-License-Identifier: MIT
*******************************************************************************/
/**
* This module provides basic file I/O operations: reading and writing bytes from/to a file.
* The provided API is intentionally limited in scope and will be expanded later.
*
* Where the API accepts file paths as strings, there are some limitations.
* File paths containing only ASCII characters work identically across languages and platforms;
* non-ASCII Unicode codepoints may cause different language- or platform-specific behavior.
*
* File path symbols including . and .. are allowed.
*/
module Std.FileIO {
import opened Wrappers
import FileIOInternalExterns
export provides ReadBytesFromFile, WriteBytesToFile, Wrappers
/*
* Public API
*/
/**
* Attempts to read all bytes from the file at the given file path.
* If an error occurs, a `Result.Failure` value is returned containing an implementation-specific
* error message (which may also contain a stack trace).
*
* NOTE: See the module description for limitations on the path argument.
*/
method ReadBytesFromFile(path: string) returns (res: Result<seq<bv8>, string>) {
var isError, bytesRead, errorMsg := FileIOInternalExterns.INTERNAL_ReadBytesFromFile(path);
return if isError then Failure(errorMsg) else Success(bytesRead);
}
/**
* Attempts to write the given bytes to the file at the given file path,
* creating nonexistent parent directories as necessary.
* If an error occurs, a `Result.Failure` value is returned containing an implementation-specific
* error message (which may also contain a stack trace).
*
* NOTE: See the module description for limitations on the path argument.
*/
method WriteBytesToFile(path: string, bytes: seq<bv8>) returns (res: Result<(), string>) {
var isError, errorMsg := FileIOInternalExterns.INTERNAL_WriteBytesToFile(path, bytes);
return if isError then Failure(errorMsg) else Success(());
}
}