mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
add client, seek, and size
This commit is contained in:
24
src/file.go
24
src/file.go
@@ -92,6 +92,30 @@ func ArRead(args ...any) (any, ArErr) {
|
||||
}
|
||||
return ArBuffer(bytes), ArErr{}
|
||||
}},
|
||||
"seek": builtinFunc{"seek", func(args ...any) (any, ArErr) {
|
||||
if len(args) != 1 {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "seek takes 1 argument, got " + fmt.Sprint(len(args)), EXISTS: true}
|
||||
}
|
||||
if typeof(args[0]) != "number" {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "seek takes a number not type '" + typeof(args[0]) + "'", EXISTS: true}
|
||||
}
|
||||
offset := args[0].(number)
|
||||
if offset.Denom().Int64() != 1 {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: "seek takes an integer not type '" + typeof(args[0]) + "'", EXISTS: true}
|
||||
}
|
||||
_, err := file.Seek(offset.Num().Int64(), io.SeekStart)
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return nil, ArErr{}
|
||||
}},
|
||||
"size": builtinFunc{"size", func(...any) (any, ArErr) {
|
||||
info, err := file.Stat()
|
||||
if err != nil {
|
||||
return ArObject{}, ArErr{TYPE: "Runtime Error", message: err.Error(), EXISTS: true}
|
||||
}
|
||||
return newNumber().SetInt64(info.Size()), ArErr{}
|
||||
}},
|
||||
}), ArErr{}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user