Permalink
Browse files

[enhance] file: added write function to File, renamed bslFile of_stri…

…ng function, added doc, updated changelog
  • Loading branch information...
1 parent 69c7108 commit 23a3bda70ffdef14884f9bc7a6b7f6232dc66b17 @Aqua-Ye Aqua-Ye committed Sep 13, 2012
View
7 CHANGELOG
@@ -1,3 +1,10 @@
+Updated APIs:
+
+ * File:
+ - depreacted `content` and `content_opt`, replaced by `read` and `read_opt`
+ - added `write` function
+
+
2012.09.10, Version 1.0.6 (stable), v3375
New features:
View
14 lib/plugins/unix/bslFile.ml
@@ -101,19 +101,19 @@ let remove_rec file = ignore (File.remove_rec file)
let last_modification f = Time.in_milliseconds (File.last_modification f)
(**
- Dump a value to a file
+ Dump a binary value to a file
- @param n The name of the file
- @param content The content to put in the file
+ @param name The name of the file
+ @param content The binary content to put in the file
In case of error, explode.
*)
- ##register of_string : string, binary -> void
- let of_string n content =
+ ##register write : string, binary -> void
+ let write name content =
let och =
- let path = Filename.dirname n in
+ let path = Filename.dirname name in
ignore (File.check_create_path path);
- open_out n
+ open_out name
in output_string och (Buf.contents content) ; close_out och
##register create_full_path: string -> void
View
2 lib/plugins/unix/bslFile.nodejs
@@ -139,7 +139,7 @@ function last_modification(path) {
/**
* @register {string, binary -> void}
*/
-function of_string(path, bin) {
+function write(path, bin) {
var dir = dirname(path);
create_full_path(dir);
FileSystem.writeFileSync(path, bin.contents);
View
2 lib/stdlib/core/web/resource/resource_private.opa
@@ -175,7 +175,7 @@ Resource_private =
//file_content = %% BslFile.content_cps %%: string -> option(string) //Works only on Macintosh
file_content = %% BslFile.content_opt %%: string -> option(binary)
file_exists = %% BslFile.exists %%: string -> bool
- file_create = %% BslFile.of_string %%: string, binary -> void
+ file_create = %% BslFile.write %%: string, binary -> void
dir_exists = %% BslFile.is_directory %%: string -> bool
dir_create = %% BslFile.create_full_path %%: string -> void
//get_base_name = %% BslFile.basename %%: string -> string
View
2 lib/stdlib/core/web/server/server_private.opa
@@ -401,7 +401,7 @@ Server_private = {{
if debug then
// Note: these bypasses are defined locally to avoid unsafe abuse of the library
file_content = %% BslFile.content %% : string -> binary
- file_of_string = %% BslFile.of_string %% : string, binary -> void
+ file_of_string = %% BslFile.write %% : string, binary -> void
file_exists = %% BslFile.exists %% : string -> bool
// TODO: put back when option will be here
//dir = match opt.get(dir_opt) with
View
2 lib/stdlib/csv/csv_export.opa
@@ -62,7 +62,7 @@ to_string(config, content) =
*/
to_file(config, content, filename) =
csv_s = to_string(config, content)
- %%BslFile.of_string%%(filename, binary_of_string(csv_s))
+ %%BslFile.write%%(filename, binary_of_string(csv_s))
/**
* Generate a new binary resource from the given list of string list
View
63 lib/stdlib/io/file/file.opa
@@ -11,16 +11,6 @@
*/
import-plugin unix
-/**
- * {1 About this module}
- *
- * Be aware that this package access local file
- * and could be inaccessible or not working with some cloud configuration
- *
- * {1 Where should I start?}
- *
- * {1 What if I need more?}
- */
/**
* {1 Interface}
@@ -46,19 +36,64 @@ type File.onchange = {persistent:bool}
/**
* A module for very basic file access
+ *
+ * Be aware that this package access local file
+ * and could be inaccessible or not working with some cloud configuration
*/
File = {{
- exists = %% BslFile.exists %% : string -> bool
- content = %% BslFile.content %% : string -> binary
- content_opt = %% BslFile.content_opt %% : string -> option(binary)
- is_directory = %% BslFile.is_directory %% : string -> bool
+
+ /**
+ * Read the content of a file
+ *
+ * @param path The path of the file
+ * @return The binary content
+ */
+ read(path) = %% BslFile.content %%(path)
+ @deprecated({use="read"})
+ content = read
+
+ /**
+ * Read the content of a file
+ *
+ * @param path The path of the file
+ * @return The optional binary content
+ */
+ read_opt(path) = %% BslFile.content_opt %%(path)
+ @deprecated({use="read_opt"})
+ content_opt = read_opt
+
+ /**
+ * Write a binary value to a file
+ *
+ * @param path The path of the file
+ * @param content The binary content to put in the file
+ */
+ write(path, content) = %% BslFile.write %%(path, content)
+
+ /**
+ * Check the existence of a file
+ *
+ * @param path The path of the file to check
+ * @return true if the file exists
+ */
+ exists(path) = %% BslFile.exists %%(path)
+
+ /**
+ * Check if the given path is a directory
+ *
+ * @param path The path to test
+ * @return true if the path is a directory
+ */
+ is_directory(path) = %% BslFile.is_directory %%(path)
+
/** Warning: not working on node backend */
mimetype =
#<Ifstatic:OPA_BACKEND_QMLJS>
_ -> none
#<Else>
%% BslFile.mimetype_opt %% : string -> option(string)
#<End>
+
basename = %% BslFile.basename %% : string -> string
dirname = %% BslFile.dirname %% : string -> string
View
2 lib/stdlib/xls/xls_export.opa
@@ -82,7 +82,7 @@ to_string(config, content) =
*/
to_file(config, content, filename) =
xls_s = to_string(config, content)
- %%BslFile.of_string%%(filename, binary_of_string(xls_s))
+ %%BslFile.write%%(filename, binary_of_string(xls_s))
/**
* Generate a new binary resource from the given list of string list

0 comments on commit 23a3bda

Please sign in to comment.