fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
057f33f
v2.1.3
1function io . copy ( pathFrom , pathTo ) 2local fileFrom , err =io . open ( pathFrom , "rb" ) 3if not fileFrom then return false , err end 4 5local fileTo , err =io . open ( pathTo , "wb" ) 6if not fileTo then return false , err end 7 8fileTo : write ( fileFrom : read ( "*all" )) 9 10io . close ( fileFrom ) 11io . close ( fileTo ) 12return true 13end 14 15function io . exists ( path ) 16local file =io . open ( path , "r" ) 17if file then 18io . close ( file ) 19return true 20end 21return false 22end 23 24function io . readfile ( path ) 25local file =io . open ( path , "r" ) 26if file then 27local content =file : read ( "*a" ) 28io . close ( file ) 29return content 30end 31return nil 32end 33 34function io . writefile ( path , content , mode ) 35mode =mode or "w+b" 36local file =io . open ( path , mode ) 37if file then 38if file : write ( content ) == nil then return false end 39io . close ( file ) 40return true 41else 42return false 43end 44end 45 46function io . pathinfo ( path ) 47local pos =string . len ( path ) 48local extpos =pos + 1 49while pos > 0 do 50local b =string . byte ( path , pos ) 51if b == 46 then -- 46 = char "." 52extpos =pos 53elseif b == 47 then -- 47 = char "/" 54break 55end 56pos =pos - 1 57end 58 59local dirname =string . sub ( path , 1 , pos ) 60local filename =string . sub ( path , pos + 1 ) 61extpos =extpos - pos 62local basename =string . sub ( filename , 1 , extpos - 1 ) 63local extname =string . sub ( filename , extpos ) 64return { 65dirname =dirname , 66filename =filename , 67basename =basename , 68extname =extname 69} 70end 71 72function io . filesize ( path ) 73local size =false 74local file =io . open ( path , "r" ) 75if file then 76local current =file : seek () 77size =file : seek ( "end" ) 78file : seek ( "set" , current ) 79io . close ( file ) 80end 81return size 82end