forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.go
37 lines (30 loc) · 727 Bytes
/
file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package libkb
import (
"io"
"os"
)
// File defines a default SafeWriter implementation
type File struct {
filename string
data []byte
perm os.FileMode
}
// NewFile returns a File
func NewFile(filename string, data []byte, perm os.FileMode) File {
return File{filename, data, perm}
}
// Save file
func (f File) Save() error {
return SafeWriteToFile(f, f.perm)
}
// GetFilename is for SafeWriter
func (f File) GetFilename() string {
return f.filename
}
// WriteTo is for SafeWriter
func (f File) WriteTo(w io.Writer) (int64, error) {
n, err := w.Write(f.data)
return int64(n), err
}