char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
dea05b4
main
1import { 2op_file_chmod_sync as chmodOp , 3op_file_chown_sync as chownOp , 4op_file_copy_sync as copyOp , 5op_file_lchown_sync as lchownOp , 6op_file_link_sync as linkOp , 7op_file_lutime_sync as lutimeOp , 8op_file_mkdir_sync as mkdirOp , 9op_file_open_sync as openOp , 10op_file_path_stat_sync as pathStatOp , 11op_file_path_truncate_sync as truncatePathOp , 12op_file_read_dir_sync as readDirOp , 13op_file_read_link_sync as readLinkOp , 14op_file_real_path_sync as realPathOp , 15op_file_remove_sync as removeOp , 16op_file_rename_sync as renameOp , 17op_file_symlink_sync as symlinkOp , 18op_file_utime_sync as utimeOp , 19} from "ext:core/ops" ; 20import { dictionary , required } from "ext:web/idl.js" ; 21import { RangeError , TypeError } from "ext:core/primordials" ; 22import { 23args , 24fileHandle , 25integer , 26metadata , 27mode , 28openArgs , 29owner , 30path , 31stamp , 32} from "./main.js" ; 33import { result } from "./errors.js" ; 34 35export { errors , FileHandle , SeekMode } from "./main.js" ; 36 37export function open ( pathname :unknown , options :unknown = undefined ) { 38required ( arguments . length , 1 ); 39return fileHandle ( result ( openOp ( openArgs ( pathname , options )))); 40} 41export function create ( pathname :unknown ) { 42required ( arguments . length , 1 ); 43return open ( pathname , { 44read :true , 45write :true , 46create :true , 47truncate :true , 48}); 49} 50export function stat ( pathname :unknown ) { 51required ( arguments . length , 1 ); 52return metadata ( 53result ( pathStatOp ( args ( path ( pathname ), true ))), 54); 55} 56export function lstat ( pathname :unknown ) { 57required ( arguments . length , 1 ); 58return metadata ( 59result ( pathStatOp ( args ( path ( pathname ), false ))), 60); 61} 62export function * readDir ( 63pathname :unknown , 64) :Generator < 65{ name :string ; isFile :boolean ; isDirectory :boolean ; isSymlink :boolean } 66> { 67required ( arguments . length , 1 ); 68const entries = result ( readDirOp ( path ( pathname ))); 69for ( let i = 0 ; i < entries . length ; i ++ ) { 70const row = entries [ i ]; 71yield { 72name :row [ 0 ], 73isFile :row [ 1 ], 74isDirectory :row [ 2 ], 75isSymlink :row [ 3 ], 76}; 77} 78} 79export function mkdir ( pathname :unknown , options :unknown = undefined ) :void { 80required ( arguments . length , 1 ); 81const filename = path ( pathname ), mode = dictionary ( options ). mode ; 82if ( mode !== undefined && integer ( mode ) > 0o7777 ) { 83throw new RangeError ( "Invalid directory mode" ); 84} 85result ( 86mkdirOp ( args ( filename , mode === undefined ?null :mode as number )), 87); 88} 89export function remove ( pathname :unknown , options :unknown = undefined ) :void { 90required ( arguments . length , 1 ); 91const filename = path ( pathname ), recursive = dictionary ( options ). recursive ; 92if ( recursive !== undefined && typeof recursive !== "boolean" ) { 93throw new TypeError ( "recursive must be boolean" ); 94} 95result ( removeOp ( args ( filename , recursive === true ))); 96} 97export function rename ( source :unknown , destination :unknown ) :void { 98required ( arguments . length , 2 ); 99result ( renameOp ( args ( path ( source ), path ( destination )))); 100} 101export function copyFile ( source :unknown , destination :unknown ) :void { 102required ( arguments . length , 2 ); 103result ( copyOp ( args ( path ( source ), path ( destination )))); 104} 105export function symlink ( 106target :unknown , 107linkPath :unknown , 108options :unknown = undefined , 109) :void { 110required ( arguments . length , 2 ); 111const contents = path ( target ), 112link = path ( linkPath ), 113kind = dictionary ( options ). type ; 114if ( kind !== undefined && kind !== "file" && kind !== "dir" ) { 115throw new TypeError ( "Symlink type must be file or dir" ); 116} 117result ( 118symlinkOp ( args ( contents , link , kind === undefined ?null :kind )), 119); 120} 121export function readLink ( pathname :unknown ) :string { 122required ( arguments . length , 1 ); 123return result ( readLinkOp ( path ( pathname ))); 124} 125export function realPath ( pathname :unknown ) :string { 126required ( arguments . length , 1 ); 127return result ( realPathOp ( path ( pathname ))); 128} 129export function chmod ( pathname :unknown , fileMode :number ) :void { 130required ( arguments . length , 2 ); 131result ( chmodOp ( args ( path ( pathname ), mode ( fileMode )))); 132} 133export function chown ( 134pathname :unknown , 135uid :number | null | undefined , 136gid :number | null | undefined , 137) :void { 138required ( arguments . length , 3 ); 139result ( 140chownOp ( args ( path ( pathname ), owner ( uid ), owner ( gid ))), 141); 142} 143export function lchown ( 144pathname :unknown , 145uid :number | null | undefined , 146gid :number | null | undefined , 147) :void { 148required ( arguments . length , 3 ); 149result ( 150lchownOp ( args ( path ( pathname ), owner ( uid ), owner ( gid ))), 151); 152} 153export function utime ( 154pathname :unknown , 155atime :number | Date , 156mtime :number | Date , 157) :void { 158required ( arguments . length , 3 ); 159const before = stamp ( atime ), after = stamp ( mtime ); 160result ( 161utimeOp ( 162args ( path ( pathname ), before [ 0 ], before [ 1 ], after [ 0 ], after [ 1 ]), 163), 164); 165} 166export function lutime ( 167pathname :unknown , 168atime :number | Date , 169mtime :number | Date , 170) :void { 171required ( arguments . length , 3 ); 172const before = stamp ( atime ), after = stamp ( mtime ); 173result ( 174lutimeOp ( 175args ( path ( pathname ), before [ 0 ], before [ 1 ], after [ 0 ], after [ 1 ]), 176), 177); 178} 179export function link ( oldpath :unknown , newpath :unknown ) :void { 180required ( arguments . length , 2 ); 181result ( linkOp ( args ( path ( oldpath ), path ( newpath )))); 182} 183export function truncate ( pathname :unknown , length = 0 ) :void { 184required ( arguments . length , 1 ); 185result ( 186truncatePathOp ( args ( path ( pathname ), integer ( length ))), 187); 188}