summaryrefslogtreecommitdiff
path: root/internal/utils/bytes.go
blob: c8443728dee78943893f93cb02476b178a571f57 (plain)
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
package utils

// BytesJoin is an alternate form of bytes.Join which doesn't use a sep.
func BytesJoin(s ...[]byte) (dst []byte) {
	if len(s) == 0 {
		return []byte{}
	}

	if len(s) == 1 {
		return append([]byte(nil), s[0]...)
	}

	var (
		n, dstp int
	)

	for _, v := range s {
		n += len(v)
	}

	dst = make([]byte, n)

	for _, v := range s {
		dstp += copy(dst[dstp:], v)
	}

	return dst
}