aboutsummaryrefslogtreecommitdiff
path: root/lib/bytes/bytes.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2019-02-14 23:28:25 +0700
committerShulhan <ms@kilabit.info>2019-02-14 23:28:25 +0700
commit49e72c835ca2580194116e0739b82dd9e881618c (patch)
treebf1f19ea91da9be4610b1a1310c5d91b75126e08 /lib/bytes/bytes.go
parent99eb4218908b059e403a18d2dd125452ca3176f0 (diff)
downloadpakakeh.go-49e72c835ca2580194116e0739b82dd9e881618c.tar.xz
bytes: add function to copy slice
This function is combination of make() and copy().
Diffstat (limited to 'lib/bytes/bytes.go')
-rw-r--r--lib/bytes/bytes.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/bytes/bytes.go b/lib/bytes/bytes.go
index 55c8a308..63a502ab 100644
--- a/lib/bytes/bytes.go
+++ b/lib/bytes/bytes.go
@@ -69,6 +69,19 @@ func AppendUint32(data *[]byte, v uint32) {
}
//
+// Copy slice of bytes from parameter.
+//
+func Copy(src []byte) (dst *[]byte) {
+ if src == nil || len(src) == 0 {
+ return nil
+ }
+ cp := make([]byte, len(src))
+ copy(cp, src)
+ dst = &cp
+ return
+}
+
+//
// CutUntilToken cut line until we found token.
//
// If token found, it will return all cutted bytes before token, positition of