fs.file
Deprecated: every function forwards to fs. Write import fs instead of import fs.file.
import fs.file
The fs.file package is deprecated. Everything in it now lives in fs, and each function here only calls its fs twin, so old programs keep compiling and behave the same. In new code write import fs and call fs.ReadText(path), fs.WriteText(path, text), fs.Copy(src, dst) and the rest straight from fs. file.FileInfo is the same type as fs.FileInfo, so values pass between the two without conversion.
To migrate, change import fs.file to import fs and replace each file. prefix with fs.. The names, arguments and results are exactly the same. See the fs page for the guides and the full description of each function.
Move old code to fs
Change import fs.file to import fs and the file. prefix of every call to fs.. Nothing else changes: file.ReadText(p) becomes fs.ReadText(p), file.Stat(p) becomes fs.Stat(p), and a variable declared as file.FileInfo may be passed wherever fs.FileInfo is expected.
Using both in one program
A program may import fs and fs.file together while it is being migrated. Both prefixes call the same code, so the results are identical, and the compiler does not treat the two FileInfo names as different types.
Types
FileInfo
type FileInfo = fs.FileInfoimport fs
import fs.file
func main:
file.WriteText("legacy.txt", "old code")
println file.ReadText("legacy.txt"), fs.ReadText("legacy.txt")
println file.Size("legacy.txt") == fs.Size("legacy.txt"), file.Exists("legacy.txt")
info := file.Stat("legacy.txt")
println info.exists, info.size
file.Delete("legacy.txt")
println fs.Exists("legacy.txt")
endFunctions
Open
func Open(path: str, mode: str): File*fs.Open.The example for this item is shown with the ones above: fs-file-Migrate.salam
Close
func Close(f: File*)fs.Close.The example for this item is shown with the ones above: fs-file-Migrate.salam
ReadText
func ReadText(path: str): strfs.ReadText.The example for this item is shown with the ones above: fs-file-Migrate.salam
ReadAll
func ReadAll(path: str): strfs.ReadAll.The example for this item is shown with the ones above: fs-file-Migrate.salam
ReadBytes
func ReadBytes(path: str, n: int): strfs.ReadBytes.The example for this item is shown with the ones above: fs-file-Migrate.salam
ReadLines
func ReadLines(path: str): Vector<str>fs.ReadLines.The example for this item is shown with the ones above: fs-file-Migrate.salam
WriteText
func WriteText(path: str, data: str): intfs.WriteText.The example for this item is shown with the ones above: fs-file-Migrate.salam
WriteBytes
func WriteBytes(path: str, data: str): intfs.WriteBytes.The example for this item is shown with the ones above: fs-file-Migrate.salam
Append
func Append(path: str, data: str): intfs.Append.The example for this item is shown with the ones above: fs-file-Migrate.salam
AtomicWrite
func AtomicWrite(path: str, data: str): intfs.AtomicWrite.The example for this item is shown with the ones above: fs-file-Migrate.salam
Size
func Size(p: str): i64fs.Size.The example for this item is shown with the ones above: fs-file-Migrate.salam
ModTime
func ModTime(p: str): i64fs.ModTime.The example for this item is shown with the ones above: fs-file-Migrate.salam
AccessedTime
func AccessedTime(p: str): i64fs.AccessedTime.The example for this item is shown with the ones above: fs-file-Migrate.salam
CreatedTime
func CreatedTime(p: str): i64fs.CreatedTime.The example for this item is shown with the ones above: fs-file-Migrate.salam
Permissions
func Permissions(p: str): intfs.Permissions.The example for this item is shown with the ones above: fs-file-Migrate.salam
Chmod
func Chmod(p: str, mode: int): intfs.Chmod.The example for this item is shown with the ones above: fs-file-Migrate.salam
Extension
func Extension(p: str): strfs.Extension.The example for this item is shown with the ones above: fs-file-Migrate.salam
MimeType
func MimeType(p: str): strfs.MimeType.The example for this item is shown with the ones above: fs-file-Migrate.salam
Stat
func Stat(p: str): FileInfofs.Stat.The example for this item is shown with the ones above: fs-file-Migrate.salam
Copy
func Copy(src: str, dst: str): intfs.Copy.The example for this item is shown with the ones above: fs-file-Migrate.salam
Move
func Move(src: str, dst: str): intfs.Move.The example for this item is shown with the ones above: fs-file-Migrate.salam
Rename
func Rename(src: str, dst: str): intfs.Rename.The example for this item is shown with the ones above: fs-file-Migrate.salam
Delete
func Delete(p: str): intfs.Delete.The example for this item is shown with the ones above: fs-file-Migrate.salam
Exists
func Exists(p: str): boolfs.Exists.The example for this item is shown with the ones above: fs-file-Migrate.salam
Md5Hex
func Md5Hex(p: str): strfs.Md5Hex.The example for this item is shown with the ones above: fs-file-Migrate.salam
Sha1Hex
func Sha1Hex(p: str): strfs.Sha1Hex.The example for this item is shown with the ones above: fs-file-Migrate.salam
Sha256Hex
func Sha256Hex(p: str): strfs.Sha256Hex.The example for this item is shown with the ones above: fs-file-Migrate.salam
Sha512Hex
func Sha512Hex(p: str): strfs.Sha512Hex.The example for this item is shown with the ones above: fs-file-Migrate.salam