From 5b60a38a471610dc77c94f153addec277a0afa01 Mon Sep 17 00:00:00 2001 From: funshine Date: Mon, 10 Nov 2014 17:16:07 +0800 Subject: [PATCH] modify readme --- README.md | 225 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 115 insertions(+), 110 deletions(-) diff --git a/README.md b/README.md index de526afe..56f38e72 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ ###version 0.1 2014-10-11 ###change log: +2014-11-10
+change log module to file module
+now file operation support multiple read/write
+for now file module only allowed one file opened
+ 2014-11-5
delete log operation api from node module
add log module
@@ -206,14 +211,73 @@ nil ####See also **-** []() -#log module - -## log.format() +#file module + +## file.remove() ####Description -format flash for users. +remove file from user flash. ####Syntax -log.format() +file.remove(filename) + +####Parameters +filename: file to be removed + +####Returns +nil + +####Example + +``` + //remove "foo.lua" from user flash. + file.remove("foo.lua") +``` + +####See also +**-** [file.open()](#fl_open)
+**-** [file.close()](#fl_close) + + +## file.open() +####Description +open file. + +####Syntax +file.open(filename, mode) + +####Parameters +filename: file to be opened, directories are not supported
+mode:
+ "r": read mode (the default)
+ "w": write mode
+ "a": append mode
+ "r+": update mode, all previous data is preserved
+ "w+": update mode, all previous data is erased
+ "a+": append update mode, previous data is preserved, writing is only allowed at the end of file + +####Returns +nil + +####Example + +``` + //open 'init.lua', print the first line. + file.open("init.lua", "r") + print(file.readline()) + file.close() +``` + +####See also +**-** [file.close()](#fl_close)
+**-** [file.readline()](#fl_readline) + + +## file.close() +####Description +close the file. + +####Syntax +file.close() ####Parameters nil @@ -224,114 +288,53 @@ nil ####Example ``` - //record log to init.lua. Call the file after system restart. - log.format() - log.start("init.lua", 1) - print("hello world") - log.stop() + //open 'init.lua', print the first line. + file.open("init.lua", "r") + print(file.readline()) + file.close() ``` ####See also -**-** [log.start()](#lg_start)
-**-** [log.stop()](#lg_stop) +**-** [file.open()](#fl_open)
+**-** [file.readline()](#fl_readline) - -## log.start() + +## file.readline() ####Description -start to log input +read one line of file which is opened before line by line. ####Syntax -log.start(filename, noparse) - -####Parameters - -filename: log file, directories are not supported
-noparse: 1 for lua VM doesn’t parse input, 0 for lua VM parse input - -####Returns -nil - -####Example - -``` - //record log to init.lua. Call the file after system restart. - log.format() - log.start("init.lua", 1) - print("hello world") - log.stop() - //At this point, the content of init.lua is "print("hello world")". When system restart, print("hello world") are excuted. -``` - -####See also -**-** [log.format()](#lg_format)
-**-** [log.stop()](#lg_stop) - - -## log.stop() -####Description -stop log. - -####Syntax -log.stop() +file.readline() ####Parameters nil ####Returns -nil - -####Example - -``` - //record log to init.lua. Call the file after system restart. - log.format() - log.start("init.lua", 1) - print("hello world") - log.stop() - //At this point, the content of init.lua is "print("hello world")". When system restart, print("hello world") are excuted. -``` - -####See also -**-** [log.format()](#lg_format)
-**-** [log.start()](#lg_start) - - -## log.open() -####Description -open the log file - -####Syntax -log.open(filename) - -####Parameters -filename: log file, directories are not supported - -####Returns -nil +file content in string, line by line ####Example ``` //print the first line of 'init.lua' - log.open("init.lua") - print(log.readline()) - log.close() + file.open("init.lua", "r") + print(file.readline()) + file.close() ``` ####See also -**-** [log.close()](#lg_close)
-**-** [log.readline()](#lg_readline) +**-** [file.open()](#fl_open)
+**-** [file.close()](#fl_close) - -## log.close() + +## file.writeline() ####Description -close the log file which opened before +write new line to file with a '\n' at the end. ####Syntax -log.close() +file.writeline(string) ####Parameters -nil +string: content to be write to file ####Returns nil @@ -339,50 +342,52 @@ nil ####Example ``` - //print the first line of 'init.lua' - log.open("init.lua") - print(log.readline()) - log.close() + //open 'init.lua' in 'a+' mode + file.open("init.lua", "a+") + //write 'foo bar' to the end of the file + file.writeline('foo bar') + file.close() ``` ####See also -**-** [log.open()](#lg_open)
-**-** [log.readline()](#lg_readline) +**-** [file.open()](#fl_open)
+**-** [file.write()](#fl_write) - -## log.readline() + +## file.write() ####Description -read log file which is opened before line by line. +write string to file. ####Syntax -log.readline() +file.write(string) ####Parameters -nil +string: content to be write to file. ####Returns -log file content in string, line by line +nil ####Example ``` - //print the first line of 'init.lua' - log.open("init.lua") - print(log.readline()) - log.close() + //open 'init.lua' in 'a+' mode + file.open("init.lua", "a+") + //write 'foo bar' to the end of the file + file.write('foo bar') + file.close() ``` ####See also -**-** [log.open()](#lg_open) -**-** [log.close()](#lg_close) +**-** [file.open()](#fl_open)
+**-** [file.writeline()](#fl_writeline) - -## log.list() + +## file.list() ####Description list all files. ####Syntax -log.list() +file.list() ####Parameters nil @@ -393,14 +398,14 @@ a lua table which contains the {file name: file size} pairs ####Example ``` - l = log.list(); + l = file.list(); for k,v in l do print("name:"..k..", size:"..v) end ``` ####See also -**-** [log.format()](#lg_format) +**-** [file.remove()](#fl_remove) #wifi module ##CONSTANT