Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File = {
- new = function( self, filePath )
- if self.__index then
- return setmetatable( { }, { __index = self } )
- else
- return setmetatable( { fPath = filePath, buffer = "" }, { __index = File } )
- end
- end,
- exist = function( self, filePath )
- if self.__index then
- if self.fPath then
- return fileExists( self.fPath )
- end
- return false
- else
- return fileExists( filePath )
- end
- end,
- rename = function( self, filePath, newFilePath )
- if self.__index then
- if self.fPath then
- local res = fileRename( self.fPath, filePath )
- self.fPath = filePath
- return res
- end
- return false
- else
- return fileRename( filePath, newFilePath )
- end
- end,
- delete = function( self, filePath )
- if self.__index then
- if self.fPath then
- return fileDelete( self.fPath )
- end
- return false
- else
- return fileDelete( filePath )
- end
- end,
- create = function( self, filePath )
- if not self.file then
- self.fPath = filePath or self.fPath
- self.file = fileCreate( self.fPath )
- return self.file ~= false
- end
- return false
- end,
- open = function( self, readOnly, filePath )
- if not self.file then
- self.fPath = filePath or self.fPath
- self.file = fileOpen( self.fPath, readOnly or false )
- return self.file ~= false
- end
- return false
- end,
- close = function( self )
- if self.file then
- local res = fileClose( self.file )
- self.file = nil
- self.buffer = ""
- return res
- end
- return false
- end,
- pos = function( self, offset )
- if self.file then
- if offset then
- return fileSetPos( self.file, offset )
- else
- return fileGetPos( self.file )
- end
- end
- return false
- end,
- size = function( self, filePath )
- if filePath then
- local hFile = fileOpen( filePath )
- if hFile then
- local fSize = fileGetSize( hFile )
- fileClose( hFile )
- return fSize
- end
- elseif self.file then
- return fileGetPos( self.file )
- end
- return false
- end,
- flush = function( self )
- if self.file then
- return fileFlush( self.file )
- end
- return false
- end,
- write = function( self, string1, ... )
- if self.file then
- return fileWrite( self.file, string1, ... )
- end
- return false
- end,
- read = function( self, count )
- if self.file then
- return fileRead( self.file, count )
- end
- return false
- end,
- readLine = function( self, count )
- if self.file then
- while true do
- local endpos = string.find( self.buffer, "\n" )
- if not endpos then
- if fileIsEOF( self.file ) then
- if self.buffer ~= "" then
- local line = self.buffer
- self.buffer = ""
- return line
- else
- return false
- end
- end
- self.buffer = self.buffer .. fileRead( self.file, count or 500 )
- else
- local line = string.sub( self.buffer, 1, endpos - 1 )
- self.buffer = string.sub( self.buffer, endpos + 1 )
- return line
- end
- end
- end
- return false
- end,
- EOF = function( self )
- if self.file then
- return fileIsEOF( self.file )
- end
- return false
- end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement