@@ -75,6 +75,12 @@ defmodule File do
7575 @ type posix :: :file . posix ( )
7676 @ type io_device :: :file . io_device ( )
7777 @ type stat_options :: [ time: :local | :universal | :posix ]
78+ @ type mode :: :append | :binary | :compressed | :delayed_write | :exclusive |
79+ :raw | :read | :read_ahead | :sync | :write |
80+ { :encoding , :latin1 | :unicode | :utf16 | :utf32 | :utf8 |
81+ { :utf16 , :big | :little } | { :utf32 , :big | :little } } |
82+ { :read_ahead , pos_integer } |
83+ { :delayed_write , non_neg_integer , non_neg_integer }
7884
7985 @ doc """
8086 Returns `true` if the path is a regular file.
@@ -612,15 +618,15 @@ defmodule File do
612618
613619 Check `File.open/2` for other available options.
614620 """
615- @ spec write ( Path . t , iodata , list ) :: :ok | { :error , posix }
621+ @ spec write ( Path . t , iodata , [ mode ] ) :: :ok | { :error , posix }
616622 def write ( path , content , modes \\ [ ] ) do
617623 F . write_file ( IO . chardata_to_string ( path ) , content , modes )
618624 end
619625
620626 @ doc """
621627 Same as `write/3` but raises an exception if it fails, returns `:ok` otherwise.
622628 """
623- @ spec write! ( Path . t , iodata , list ) :: :ok | no_return
629+ @ spec write! ( Path . t , iodata , [ mode ] ) :: :ok | no_return
624630 def write! ( path , content , modes \\ [ ] ) do
625631 path = IO . chardata_to_string ( path )
626632 case F . write_file ( path , content , modes ) do
@@ -902,7 +908,8 @@ defmodule File do
902908 File.close(file)
903909
904910 """
905- @ spec open ( Path . t , list ) :: { :ok , io_device } | { :error , posix }
911+ @ spec open ( Path . t , [ mode | :ram ] ) :: { :ok , io_device } | { :error , posix }
912+ @ spec open ( Path . t , ( io_device -> res ) ) :: { :ok , res } | { :error , posix } when res: var
906913 def open ( path , modes \\ [ ] )
907914
908915 def open ( path , modes ) when is_list ( modes ) do
@@ -935,7 +942,7 @@ defmodule File do
935942 end)
936943
937944 """
938- @ spec open ( Path . t , list , ( io_device -> res ) ) :: { :ok , res } | { :error , posix } when res: var
945+ @ spec open ( Path . t , [ mode | :ram ] , ( io_device -> res ) ) :: { :ok , res } | { :error , posix } when res: var
939946 def open ( path , modes , function ) do
940947 case open ( path , modes ) do
941948 { :ok , device } ->
@@ -953,7 +960,7 @@ defmodule File do
953960
954961 Returns the `io_device` otherwise.
955962 """
956- @ spec open! ( Path . t , list ) :: io_device | no_return
963+ @ spec open! ( Path . t , [ mode ] ) :: io_device | no_return
957964 def open! ( path , modes \\ [ ] ) do
958965 path = IO . chardata_to_string ( path )
959966 case open ( path , modes ) do
@@ -968,7 +975,7 @@ defmodule File do
968975
969976 Returns the function result otherwise.
970977 """
971- @ spec open! ( Path . t , list , ( io_device -> res ) ) :: res | no_return when res: var
978+ @ spec open! ( Path . t , [ mode | :ram ] , ( io_device -> res ) ) :: res | no_return when res: var
972979 def open! ( path , modes , function ) do
973980 path = IO . chardata_to_string ( path )
974981 case open ( path , modes , function ) do
@@ -1124,15 +1131,15 @@ defmodule File do
11241131 Returns `:ok` on success, or `{:error, reason}`
11251132 on failure.
11261133 """
1127- @ spec chmod ( Path . t , integer ) :: :ok | { :error , posix }
1134+ @ spec chmod ( Path . t , non_neg_integer ) :: :ok | { :error , posix }
11281135 def chmod ( path , mode ) do
11291136 F . change_mode ( IO . chardata_to_string ( path ) , mode )
11301137 end
11311138
11321139 @ doc """
11331140 Same as `chmod/2`, but raises an exception in case of failure. Otherwise `:ok`.
11341141 """
1135- @ spec chmod! ( Path . t , integer ) :: :ok | no_return
1142+ @ spec chmod! ( Path . t , non_neg_integer ) :: :ok | no_return
11361143 def chmod! ( path , mode ) do
11371144 path = IO . chardata_to_string ( path )
11381145 case chmod ( path , mode ) do
@@ -1147,15 +1154,15 @@ defmodule File do
11471154 for a given `file`. Returns `:ok` on success, or
11481155 `{:error, reason}` on failure.
11491156 """
1150- @ spec chgrp ( Path . t , integer ) :: :ok | { :error , posix }
1157+ @ spec chgrp ( Path . t , non_neg_integer ) :: :ok | { :error , posix }
11511158 def chgrp ( path , gid ) do
11521159 F . change_group ( IO . chardata_to_string ( path ) , gid )
11531160 end
11541161
11551162 @ doc """
11561163 Same as `chgrp/2`, but raises an exception in case of failure. Otherwise `:ok`.
11571164 """
1158- @ spec chgrp! ( Path . t , integer ) :: :ok | no_return
1165+ @ spec chgrp! ( Path . t , non_neg_integer ) :: :ok | no_return
11591166 def chgrp! ( path , gid ) do
11601167 path = IO . chardata_to_string ( path )
11611168 case chgrp ( path , gid ) do
@@ -1170,15 +1177,15 @@ defmodule File do
11701177 for a given `file`. Returns `:ok` on success,
11711178 or `{:error, reason}` on failure.
11721179 """
1173- @ spec chown ( Path . t , integer ) :: :ok | { :error , posix }
1180+ @ spec chown ( Path . t , non_neg_integer ) :: :ok | { :error , posix }
11741181 def chown ( path , uid ) do
11751182 F . change_owner ( IO . chardata_to_string ( path ) , uid )
11761183 end
11771184
11781185 @ doc """
11791186 Same as `chown/2`, but raises an exception in case of failure. Otherwise `:ok`.
11801187 """
1181- @ spec chown! ( Path . t , integer ) :: :ok | no_return
1188+ @ spec chown! ( Path . t , non_neg_integer ) :: :ok | no_return
11821189 def chown! ( path , uid ) do
11831190 path = IO . chardata_to_string ( path )
11841191 case chown ( path , uid ) do
0 commit comments