You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2021/07/27 17:05:05 UTC
[mynewt-artifact] branch master updated: image: Function to convert
image to a byte slice
This is an automated email from the ASF dual-hosted git repository.
vipulrahane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-artifact.git
The following commit(s) were added to refs/heads/master by this push:
new 1794f79 image: Function to convert image to a byte slice
new 4f94303 Merge pull request #24 from ccollins476ad/image-bin
1794f79 is described below
commit 1794f7972c3c6dba99dfe3bdc85354cfe0984e3d
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Thu Jun 4 14:15:14 2020 -0700
image: Function to convert image to a byte slice
---
image/image.go | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/image/image.go b/image/image.go
index f7ef6e6..90191fc 100644
--- a/image/image.go
+++ b/image/image.go
@@ -20,6 +20,8 @@
package image
import (
+ "bufio"
+ "bytes"
"encoding/binary"
"fmt"
"io"
@@ -774,3 +776,20 @@ func DecryptHwFull(img Image, secret []byte) (Image, error) {
func (img *Image) IsEncrypted() bool {
return img.Header.Flags&IMAGE_F_ENCRYPTED != 0
}
+
+func (img *Image) Bin() ([]byte, error) {
+ b := &bytes.Buffer{}
+ w := bufio.NewWriter(b)
+
+ _, err := img.Write(w)
+ if err != nil {
+ return nil, err
+ }
+
+ err = w.Flush()
+ if err != nil {
+ return nil, err
+ }
+
+ return b.Bytes(), nil
+}