infinitime/blefs/basic.go

55 lines
1.0 KiB
Go
Raw Normal View History

package blefs
// Rename moves or renames a file or directory
func (blefs *FS) Rename(old, new string) error {
// Create move request
err := blefs.request(
FSCmdMove,
true,
uint16(len(old)),
uint16(len(new)),
old,
byte(0x00),
new,
)
if err != nil {
return err
}
var status int8
// Upon receiving 0x61 (FSResponseMove)
blefs.on(FSResponseMove, func(data []byte) error {
// Read status byte
return decode(data, &status)
})
// If status is not ok, return error
if status != FSStatusOk {
return FSError{status}
}
return nil
}
// Remove removes a file or directory
func (blefs *FS) Remove(path string) error {
// Create delete request
err := blefs.request(
FSCmdDelete,
true,
uint16(len(path)),
path,
)
if err != nil {
return err
}
var status int8
// Upon receiving 0x31 (FSResponseDelete)
blefs.on(FSResponseDelete, func(data []byte) error {
// Read status byte
return decode(data, &status)
})
if status == FSStatusError {
// If status is not ok, return error
return FSError{status}
}
return nil
}