summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2021-11-27 15:46:24 -0500
committersiddharth <s@ricketyspace.net>2021-11-27 15:46:24 -0500
commit3fc9591ad59797ad715cda35b206519f3681e296 (patch)
tree05700a4eb22eaaf5a29a54b5b0736323037033cb
parentbf7695b8d3abdf33c285febc22c582c7b12b4205 (diff)
add file package
-rw-r--r--file/file.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/file/file.go b/file/file.go
new file mode 100644
index 0000000..4267b10
--- /dev/null
+++ b/file/file.go
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: ISC
+// Copyright © 2021 siddharth <s@ricketyspace.net>
+
+package file
+
+import (
+ "io"
+ "os"
+)
+
+func Read(f *os.File) ([]byte, error) {
+ bs, chunk := make([]byte, 0), make([]byte, 10)
+ for {
+ n, err := f.Read(chunk)
+ if err != nil && err != io.EOF {
+ return bs, err
+ }
+ bs = append(bs, chunk[0:n]...)
+
+ if err == io.EOF {
+ break
+ }
+ }
+ return bs, nil
+}
+
+func Write(f *os.File, content []byte) error {
+ n, err := f.Write(content)
+ if n != len(content) {
+ return err
+ }
+ return nil
+}