Skip to content

Commit

Permalink
add file.Size()
Browse files Browse the repository at this point in the history
  • Loading branch information
apmckinlay committed Dec 17, 2024
1 parent 8485753 commit 18f2443
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion builtin/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ func (sf *suFile) reset() {
}

func (sf *suFile) size() int64 {
info, err := sf.f.(*os.File).Stat()
f := sf.f
if a, ok := sf.f.(appender); ok {
f = a.f
}
info, err := f.(*os.File).Stat()
if err != nil {
panic("File: " + err.Error())
}
Expand Down Expand Up @@ -226,6 +230,16 @@ func file_Seek(this, arg1, arg2 Value) Value {
return nil
}

var _ = method(file_Size, "()")

func file_Size(this Value) Value {
sf := sfOpen(this)
if sf.w != nil {
sf.w.Flush()
}
return Int64Val(sf.size())
}

var _ = method(file_Tell, "()")

func file_Tell(this Value) Value {
Expand Down

0 comments on commit 18f2443

Please sign in to comment.