aboutsummaryrefslogtreecommitdiff
path: root/api/paths.yaml
blob: a659ffbc3a87f3215fab52d65a4eedd6d0a65f0f (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
Path.accessed:
  short: access time
  description: >
    Gets the file access time of a file.
  return:
    type: 'Int64?'
    description: >
      A 64-bit unix epoch timestamp representing when the file or directory was last
      accessed, or `none` if no such file or directory exists.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file whose access time you want.
    follow_symlinks:
      type: 'Bool'
      default: 'yes'
      description: >
        Whether to follow symbolic links.
  example: |
    assert (./file.txt).accessed() == 1704221100
    assert (./not-a-file).accessed() == none

Path.append:
  short: append to a file
  description: >
    Appends the given text to the file at the specified path, creating the file if
    it doesn't already exist. Failure to write will result in a runtime error.
  return:
    type: 'Result'
    description: >
      Either `Success` or `Failure(reason)`.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file to append to.
    text:
      type: 'Text'
      description: >
        The text to append to the file.
    permissions:
      type: 'Int32'
      default: 'Int32(0o644)'
      description: >
        The permissions to set on the file if it is being created.
  example: |
    (./log.txt).append("extra line\n")!

Path.append_bytes:
  short: append bytes to a file
  description: >
    Appends the given bytes to the file at the specified path, creating the file if
    it doesn't already exist. Failure to write will result in a runtime error.
  return:
    type: 'Result'
    description: >
      Either `Success` or `Failure(reason)`.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file to append to.
    bytes:
      type: '[Byte]'
      description: >
        The bytes to append to the file.
    permissions:
      type: 'Int32'
      default: 'Int32(0o644)'
      description: >
        The permissions to set on the file if it is being created.
  example: |
    (./log.txt).append_bytes([104, 105])!

Path.base_name:
  short: base name of a file
  description: >
    Returns the base name of the file or directory at the specified path.
  return:
    type: 'Text'
    description: >
      The base name of the file or directory.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file or directory.
  example: |
    assert (./path/to/file.txt).base_name() == "file.txt"

Path.by_line:
  short: iterate by line
  description: >
    Returns an iterator that can be used to iterate over a file one line at a time,
    or returns none if the file could not be opened.
  return:
    type: 'func(->Text?)?'
    description: >
      An iterator that can be used to get lines from a file one at a time or
      none if the file couldn't be read.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file.
  example: |
    # Safely handle file not being readable:
    if lines := (./file.txt).by_line()
        for line in lines
            say(line.upper())
    else
        say("Couldn't read file!")

    # Assume the file is readable and error if that's not the case:
    for line in (/dev/stdin).by_line()!
        say(line.upper())

Path.lines:
  short: return the lines in a file
  description: >
    Returns a list with the lines of text in a file or returns none if the file
    could not be opened.
  return:
    type: '[Text]?'
    description: >
      A list of the lines in a file or none if the file couldn't be read.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file.
  example: |
    lines := (./file.txt).lines()!

Path.can_execute:
  short: check execute permissions
  description: >
    Returns whether or not a file can be executed by the current user/group.
  return:
    type: 'Bool'
    description: >
      `yes` if the file or directory exists and the current user has execute permissions, otherwise `no`.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file to check.
  example: |
    assert (/bin/sh).can_execute() == yes
    assert (/usr/include/stdlib.h).can_execute() == no
    assert (/non/existant/file).can_execute() == no

Path.can_read:
  short: check read permissions
  description: >
    Returns whether or not a file can be read by the current user/group.
  return:
    type: 'Bool'
    description: >
      `yes` if the file or directory exists and the current user has read permissions, otherwise `no`.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file to check.
  example: |
    assert (/usr/include/stdlib.h).can_read() == yes
    assert (/etc/shadow).can_read() == no
    assert (/non/existant/file).can_read() == no

Path.can_write:
  short: check write permissions
  description: >
    Returns whether or not a file can be written by the current user/group.
  return:
    type: 'Bool'
    description: >
      `yes` if the file or directory exists and the current user has write permissions, otherwise `no`.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file to check.
  example: |
    assert (/tmp).can_write() == yes
    assert (/etc/passwd).can_write() == no
    assert (/non/existant/file).can_write() == no

Path.changed:
  short: get the last changed time
  description: >
    Gets the file change time of a file.
  note: >
    This is the ["ctime"](https://en.wikipedia.org/wiki/Stat_(system_call)#ctime) of a file,
    which is _not_ the file creation time.
  return:
    type: 'Int64?'
    description: >
      A 64-bit unix epoch timestamp representing when the file or directory was last
      changed, or `none` if no such file or directory exists.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file whose change time you want.
    follow_symlinks:
      type: 'Bool'
      default: 'yes'
      description: >
        Whether to follow symbolic links.
  example: |
    assert (./file.txt).changed() == 1704221100
    assert (./not-a-file).changed() == none

Path.child:
  short: append a child to a path
  description: >
    Return a path that is a child of another path.
  return:
    type: 'Path'
    description: >
      A new path representing the child.
  args:
    path:
      type: 'Path'
      description: >
        The path of a directory.
    child:
      type: 'Text'
      description: >
        The name of a child file or directory.
  example: |
    assert (./directory).child("file.txt") == (./directory/file.txt)

Path.children:
  short: get children of a directory
  description: >
    Returns a list of children (files and directories) within the directory at the specified path. Optionally includes hidden files.
  return:
    type: '[Path]'
    description: >
      A list of paths for the children.
  args:
    path:
      type: 'Path'
      description: >
        The path of the directory.
    include_hidden:
      default: 'no'
      description: >
        Whether to include hidden files, which start with a `.`.
  example: |
    assert (./directory).children(include_hidden=yes) == [".git", "foo.txt"]

Path.create_directory:
  short: make a directory
  description: >
    Creates a new directory at the specified path with the given permissions. If
    any of the parent directories do not exist, they will be created as needed.
  note: >
  return:
    type: 'Result'
    description: >
      Either `Success` or `Failure(reason)`.
  args:
    path:
      type: 'Path'
      description: >
        The path of the directory to create.
    permissions:
      default: 'Int32(0o755)'
      description: >
        The permissions to set on the new directory.
    recursive:
      default: 'yes'
      description: >
        If set to `yes`, then recursively create any parent directories if they
        don't exist, otherwise fail if the parent directory does not exist. When
        set to `yes`, this function behaves like `mkdir -p`.
  example: |
    (./new_directory).create_directory()

Path.current_dir:
  short: get current directory
  description: >
    Creates a new directory at the specified path with the given permissions. If
    any of the parent directories do not exist, they will be created as needed.
  return:
    type: 'Path'
    description: >
      The absolute path of the current directory.
  args:
  example: |
    assert Path.current_dir() == (/home/user/tomo)

Path.exists:
  short: check if a path exists
  description: >
    Checks if a file or directory exists at the specified path.
  return:
    type: 'Bool'
    description: >
      `True` if the file or directory exists, `False` otherwise.
  args:
    path:
      type: 'Path'
      description: >
        The path to check.
  example: |
    assert (/).exists() == yes

Path.expand_home:
  short: 'expand ~ to $HOME'
  description: >
    For home-based paths (those starting with `~`), expand the path to replace the
    tilde with and absolute path to the user's `$HOME` directory.
  return:
    type: 'Path'
    description: >
      If the path does not start with a `~`, then return it unmodified. Otherwise,
      replace the `~` with an absolute path to the user's home directory.
  args:
    path:
      type: 'Path'
      description: >
        The path to expand.
  example: |
    # Assume current user is 'user'
    assert (~/foo).expand_home() == (/home/user/foo)
    # No change
    assert (/foo).expand_home() == (/foo)

Path.extension:
  short: get file extension
  description: >
    Returns the file extension of the file at the specified path. Optionally returns the full extension.
  return:
    type: 'Text'
    description: >
      The file extension (not including the leading `.`) or an empty text if there is
      no file extension.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file.
    full:
      type: 'Bool'
      default: 'yes'
      description: >
        Whether to return everything after the first `.` in the base name, or
        only the last part of the extension.
  example: |
    assert (./file.tar.gz).extension() == "tar.gz"
    assert (./file.tar.gz).extension(full=no) == "gz"
    assert (/foo).extension() == ""
    assert (./.git).extension() == ""

Path.files:
  short: list files in a directory
  description: >
    Returns a list of files within the directory at the specified path. Optionally includes hidden files.
  return:
    type: '[Path]'
    description: >
      A list of file paths.
  args:
    path:
      type: 'Path'
      description: >
        The path of the directory.
    include_hidden:
      type: 'Bool'
      default: 'no'
      description: >
        Whether to include hidden files.
  example: |
    assert (./directory).files(include_hidden=yes) == [(./directory/file1.txt), (./directory/file2.txt)]

Path.from_components:
  short: build a path from components
  description: >
    Returns a path built from a list of path components.
  return:
    type: 'Path'
    description: >
      A path representing the given components.
  args:
    components:
      type: '[Text]'
      description: >
        A list of path components.
  example: |
    assert Path.from_components(["/", "usr", "include"]) == (/usr/include)
    assert Path.from_components(["foo.txt"]) == (./foo.txt)
    assert Path.from_components(["~", ".local"]) == (~/.local)

Path.glob:
  short: perform file globbing
  description: >
    Perform a globbing operation and return a list of matching paths. Some glob
    specific details:

    - The paths "." and ".." are *not* included in any globbing results.

    - Files or directories that begin with "." will not match `*`, but will match `.*`.

    - Globs do support `{a,b}` syntax for matching files that match any of several
      choices of patterns.

    - The shell-style syntax `**` for matching subdirectories is not supported.
  return:
    type: '[Path]'
    description: >
      A list of file paths that match the glob.
  args:
    path:
      type: 'Path'
      description: >
        The path of the directory which may contain special globbing characters
        like `*`, `?`, or `{...}`
  example: |
    # Current directory includes: foo.txt, baz.txt, qux.jpg, .hidden
    assert (./*).glob() == [(./foo.txt), (./baz.txt), (./qux.jpg)]
    assert (./*.txt).glob() == [(./foo.txt), (./baz.txt)]
    assert (./*.{txt,jpg}).glob() == [(./foo.txt), (./baz.txt), (./qux.jpg)]
    assert (./.*).glob() == [(./.hidden)]

    # Globs with no matches return an empty list:
    assert (./*.xxx).glob() == []

Path.group:
  short: get the owning group
  description: >
    Get the owning group of a file or directory.
  return:
    type: 'Text?'
    description: >
      The name of the group which owns the file or directory, or `none` if the path does not exist.
  args:
    path:
      type: 'Path'
      description: >
        The path whose owning group to get.
    follow_symlinks:
      type: 'Bool'
      default: 'yes'
      description: >
        Whether to follow symbolic links.
  example: |
    assert (/bin).group() == "root"
    assert (/non/existent/file).group() == none

Path.has_extension:
  short: check if a path has a given extension
  description: >
    Return whether or not a path has a given file extension.
  return:
    type: 'Bool'
    description: >
      Whether or not the path has the given extension.
  args:
    path:
      type: 'Path'
      description: >
        A path.
    extension:
      type: 'Text'
      description: >
        A file extension (leading `.` is optional). If empty, the check will
        test if the file does not have any file extension.
  example: |
    assert (/foo.txt).has_extension("txt") == yes
    assert (/foo.txt).has_extension(".txt") == yes
    assert (/foo.tar.gz).has_extension("gz") == yes
    assert (/foo.tar.gz).has_extension("zip") == no

Path.is_directory:
  short: check if a path is a directory
  description: >
    Checks if the path represents a directory. Optionally follows symbolic links.
  return:
    type: 'Bool'
    description: >
      `True` if the path is a directory, `False` otherwise.
  args:
    path:
      type: 'Path'
      description: >
        The path to check.
    follow_symlinks:
      default: 'yes'
      description: >
        Whether to follow symbolic links.
  example: |
    assert (./directory/).is_directory() == yes
    assert (./file.txt).is_directory() == no

Path.is_file:
  short: check if a path is a file
  description: >
    Checks if the path represents a file. Optionally follows symbolic links.
  return:
    type: 'Bool'
    description: >
      `True` if the path is a file, `False` otherwise.
  args:
    path:
      type: 'Path'
      description: >
        The path to check.
    follow_symlinks:
      default: 'yes'
      description: >
        Whether to follow symbolic links.
  example: |
    assert (./file.txt).is_file() == yes
    assert (./directory/).is_file() == no

Path.is_socket:
  short: check if a path is a socket
  description: >
    Checks if the path represents a socket. Optionally follows symbolic links.
  return:
    type: 'Bool'
    description: >
      `True` if the path is a socket, `False` otherwise.
  args:
    path:
      type: 'Path'
      description: >
        The path to check.
    follow_symlinks:
      default: 'yes'
      description: >
        Whether to follow symbolic links.
  example: |
    assert (./socket).is_socket() == yes

Path.is_symlink:
  short: check if a path is a symbolic link
  description: >
    Checks if the path represents a symbolic link.
  return:
    type: 'Bool'
    description: >
      `True` if the path is a symbolic link, `False` otherwise.
  args:
    path:
      type: 'Path'
      description: >
        The path to check.
  example: |
    assert (./link).is_symlink() == yes

Path.modified:
  short: get file modification time
  description: >
    Gets the file modification time of a file.
  return:
    type: 'Int64?'
    description: >
      A 64-bit unix epoch timestamp representing when the file or directory was last
      modified, or `none` if no such file or directory exists.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file whose modification time you want.
    follow_symlinks:
      type: 'Bool'
      default: 'yes'
      description: >
        Whether to follow symbolic links.
  example: |
    assert (./file.txt).modified() == 1704221100
    assert (./not-a-file).modified() == none

Path.owner:
  short: get file owner
  description: >
    Get the owning user of a file or directory.
  return:
    type: 'Text?'
    description: >
      The name of the user who owns the file or directory, or `none` if the path does not exist.
  args:
    path:
      type: 'Path'
      description: >
        The path whose owner to get.
    follow_symlinks:
      type: 'Bool'
      default: 'yes'
      description: >
        Whether to follow symbolic links.
  example: |
    assert (/bin).owner() == "root"
    assert (/non/existent/file).owner() == none

Path.parent:
  short: get parent directory
  description: >
    Returns the parent directory of the file or directory at the specified path.
  return:
    type: 'Path?'
    description: >
      The path of the parent directory or `none` if the path is `(/)` (the file root).
  args:
    path:
      type: 'Path'
      description: >
        The path of the file or directory.
  example: |
    assert (./path/to/file.txt).parent() == (./path/to/)

Path.read:
  short: read file contents
  description: >
    Reads the contents of the file at the specified path or none if the file
    could not be read.
  return:
    type: 'Text?'
    description: >
      The contents of the file. If the file could not be read, none will be
      returned. If the file can be read, but is not valid UTF8 data, an error
      will be raised.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file to read.
  example: |
    assert (./hello.txt).read() == "Hello"
    assert (./nosuchfile.xxx).read() == none

Path.read_bytes:
  short: read file contents as bytes
  description: >
    Reads the contents of the file at the specified path or none if the file
    could not be read.
  return:
    type: '[Byte]?'
    description: >
      The byte contents of the file. If the file cannot be read, none will be
      returned.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file to read.
    limit:
      type: 'Int?'
      default: 'none'
      description: >
        A limit to how many bytes should be read.
  example: |
    assert (./hello.txt).read() == [72, 101, 108, 108, 111]
    assert (./nosuchfile.xxx).read() == none

Path.relative_to:
  short: apply a relative path to another
  description: >
    Returns the path relative to a given base path. By default, the base path is the current directory.
  return:
    type: 'Path'
    description: >
      A relative path from the reference point to the given path.
  args:
    path:
      type: 'Path'
      description: >
        The path to convert.
    relative_to:
      default: '(./)'
      description: >
        The base path for the relative path.
  example: |
    assert (./path/to/file.txt).relative_to((./path)) == (./to/file.txt)
    assert (/tmp/foo).relative_to((/tmp)) == (./foo)

Path.remove:
  short: remove a file or directory
  description: >
    Removes the file or directory at the specified path. A runtime error is raised if something goes wrong.
  return:
    type: 'Result'
    description: >
      Either `Success` or `Failure(reason)`.
  args:
    path:
      type: 'Path'
      description: >
        The path to remove.
    ignore_missing:
      default: 'no'
      description: >
        Whether to ignore errors if the file or directory does not exist.
  example: |
    (./file.txt).remove()

Path.resolved:
  short: resolve a path
  description: >
    Resolves the absolute path of the given path relative to a base path. By default, the base path is the current directory.
  return:
    type: 'Path'
    description: >
      The resolved absolute path.
  args:
    path:
      type: 'Path'
      description: >
        The path to resolve.
    relative_to:
      default: '(./)'
      description: >
        The base path for resolution.
  example: |
    assert (~/foo).resolved() == (/home/user/foo)
    assert (./path/to/file.txt).resolved(relative_to=(/foo)) == (/foo/path/to/file.txt)

Path.set_owner:
  short: set the owner
  description: >
    Set the owning user and/or group for a path.
  return:
    type: 'Result'
    description: >
      Either `Success` or `Failure(reason)`.
  args:
    path:
      type: 'Path'
      description: >
        The path to change the permissions for.
    owner:
      type: 'Text?'
      default: 'none'
      description: >
        If non-none, the new user to assign to be the owner of the file.
    group:
      type: 'Text?'
      default: 'none'
      description: >
        If non-none, the new group to assign to be the owner of the file.
    follow_symlinks:
      type: 'Bool'
      default: 'yes'
      description: >
        Whether to follow symbolic links.
  example: |
    (./file.txt).set_owner(owner="root", group="wheel")

Path.sibling:
  short: get another path in the same directory
  description: >
    Return a path that is a sibling of another path (i.e. has the same parent,
    but a different name). This is equivalent to `.parent().child(name)`
  return:
    type: 'Path'
    description: >
      A new path representing the sibling.
  args:
    path:
      type: 'Path'
      description: >
        A path.
    name:
      type: 'Text'
      description: >
        The name of a sibling file or directory.
  example: |
    assert (/foo/baz).sibling("doop") == (/foo/doop)

Path.subdirectories:
  short: get subdirectories
  description: >
    Returns a list of subdirectories within the directory at the specified path. Optionally includes hidden subdirectories.
  return:
    type: '[Path]'
    description: >
      A list of subdirectory paths.
  args:
    path:
      type: 'Path'
      description: >
        The path of the directory.
    include_hidden:
      default: 'no'
      description: >
        Whether to include hidden subdirectories.
  example: |
    assert (./directory).subdirectories() == [(./directory/subdir1), (./directory/subdir2)]
    assert (./directory).subdirectories(include_hidden=yes) == [(./directory/.git), (./directory/subdir1), (./directory/subdir2)]

Path.unique_directory:
  short: create a directory with a unique name
  description: >
    Generates a unique directory path based on the given path. Useful for creating temporary directories.
  return:
    type: 'Path'
    description: >
      A unique directory path after creating the directory.
  args:
    path:
      type: 'Path'
      description: >
        The base path for generating the unique directory. The last six letters of this path must be `XXXXXX`.
  example: |
    assert created := (/tmp/my-dir.XXXXXX).unique_directory() == (/tmp/my-dir-AwoxbM/)
    assert created.is_directory() == yes
    created.remove()

Path.write:
  short: write to a file
  description: >
    Writes the given text to the file at the specified path, creating the file if
    it doesn't already exist. Sets the file permissions as specified. If the file
    writing cannot be successfully completed, a runtime error is raised.
  return:
    type: 'Result'
    description: >
      Either `Success` or `Failure(reason)`.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file to write to.
    text:
      type: 'Text'
      description: >
        The text to write to the file.
    permissions:
      default: 'Int32(0o644)'
      description: >
        The permissions to set on the file if it is created.
  example: |
    (./file.txt).write("Hello, world!")

Path.writer:
  short: create a file writer
  description: >
    Returns a function that can be used to repeatedly write to the same file.
  note: >
    The file writer will keep its file descriptor open after each write (unless
    the `close` argument is set to `yes`). If the file writer is never closed,
    it will be automatically closed when the file writer is garbage collected.
  return:
    type: 'func(text:Text, close:Bool=no -> Result)'
    description: >
      Returns a function that can repeatedly write to the same file. If `close`
      is set to `yes`, then the file will be closed after writing. If this
      function is called again after closing, the file will be reopened for
      appending.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file to write to.
    append:
      type: 'Bool'
      default: 'no'
      description: >
        If set to `yes`, writes to the file will append. If set to `no`, then
        the first write to the file will overwrite its contents and subsequent
        calls will append.
    permissions:
      type: 'Int32'
      default: 'Int32(0o644)'
      description: >
        The permissions to set on the file if it is created.
  example: |
    write := (./file.txt).writer()
    write("Hello\n")!
    write("world\n", close=yes)!

Path.byte_writer:
  short: create a byte-based file writer
  description: >
    Returns a function that can be used to repeatedly write bytes to the same
    file.
  note: >
    The file writer will keep its file descriptor open after each write (unless
    the `close` argument is set to `yes`). If the file writer is never closed,
    it will be automatically closed when the file writer is garbage collected.
  return:
    type: 'func(bytes:[Byte], close:Bool=no -> Result)'
    description: >
      Returns a function that can repeatedly write bytes to the same file. If
      `close` is set to `yes`, then the file will be closed after writing. If
      this function is called again after closing, the file will be reopened
      for appending.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file to write to.
    append:
      type: 'Bool'
      default: 'no'
      description: >
        If set to `yes`, writes to the file will append. If set to `no`, then
        the first write to the file will overwrite its contents and subsequent
        calls will append.
    permissions:
      type: 'Int32'
      default: 'Int32(0o644)'
      description: >
        The permissions to set on the file if it is created.
  example: |
    write := (./file.txt).byte_writer()
    write("Hello\n".utf8())!
    write("world\n".utf8(), close=yes)!


Path.write_bytes:
  short: write bytes to a file
  description: >
    Writes the given bytes to the file at the specified path, creating the file if
    it doesn't already exist. Sets the file permissions as specified. If the file
    writing cannot be successfully completed, a runtime error is raised.
  return:
    type: 'Result'
    description: >
      Either `Success` or `Failure(reason)`.
  args:
    path:
      type: 'Path'
      description: >
        The path of the file to write to.
    bytes:
      type: '[Byte]'
      description: >
        A list of bytes to write to the file.
    permissions:
      default: 'Int32(0o644)'
      description: >
        The permissions to set on the file if it is created.
  example: |
    (./file.txt).write_bytes([104, 105])

Path.write_unique:
  short: write to a uniquely named file
  description: >
    Writes the given text to a unique file path based on the specified path. The
    file is created if it doesn't exist. This is useful for creating temporary
    files.
  return:
    type: 'Path'
    description: >
      The path of the newly created unique file.
  args:
    path:
      type: 'Path'
      description: >
        The base path for generating the unique file. This path must include
        the string `XXXXXX` in the file base name.
    text:
      type: 'Text'
      description: >
        The text to write to the file.
  example: |
    created := (./file-XXXXXX.txt).write_unique("Hello, world!")
    assert created == (./file-27QHtq.txt)
    assert created.read() == "Hello, world!"
    created.remove()

Path.write_unique_bytes:
  short: write bytes to a uniquely named file
  description: >
    Writes the given bytes to a unique file path based on the specified path. The
    file is created if it doesn't exist. This is useful for creating temporary
    files.
  return:
    type: 'Path'
    description: >
      The path of the newly created unique file.
  args:
    path:
      type: 'Path'
      description: >
        The base path for generating the unique file. This path must include
        the string `XXXXXX` in the file base name.
    bytes:
      type: '[Byte]'
      description: >
        The bytes to write to the file.
  example: |
    created := (./file-XXXXXX.txt).write_unique_bytes([1, 2, 3])
    assert created == (./file-27QHtq.txt)
    assert created.read() == [1, 2, 3]
    created.remove()