telebot/file.go

41 lines
986 B
Go
Raw Normal View History

2015-07-03 18:54:40 +00:00
package telebot
import (
"fmt"
"os"
)
// File object represents any sort of file.
type File struct {
FileID string `json:"file_id"`
2015-07-03 18:54:40 +00:00
FileSize int `json:"file_size"`
FilePath string `json:"file_path"`
2015-07-03 18:54:40 +00:00
2015-07-06 16:58:54 +00:00
// Local absolute path to file on local file system.
2015-07-03 18:54:40 +00:00
filename string
}
// NewFile attempts to create a File object, leading to a real
// file on the file system, that could be uploaded later.
//
// Notice that NewFile doesn't upload file, but only creates
// a descriptor for it.
func NewFile(path string) (File, error) {
if _, err := os.Stat(path); os.IsNotExist(err) {
return File{}, fmt.Errorf("telebot: '%s' does not exist", path)
2015-07-03 18:54:40 +00:00
}
return File{filename: path}, nil
}
2015-07-06 16:58:54 +00:00
// Exists says whether the file presents on Telegram servers or not.
2015-07-03 18:54:40 +00:00
func (f File) Exists() bool {
2015-10-13 14:38:15 +00:00
return f.FileID != ""
2015-07-03 18:54:40 +00:00
}
2015-07-06 16:58:54 +00:00
// Local returns location of file on local file system, if it's
// actually there, otherwise returns empty string.
func (f File) Local() string {
return f.filename
}