-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy pathtranslate_memcpy_comp.go
More file actions
48 lines (37 loc) · 917 Bytes
/
translate_memcpy_comp.go
File metadata and controls
48 lines (37 loc) · 917 Bytes
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
38
39
40
41
42
43
44
45
46
47
48
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/
package main
import (
"compress/gzip"
"fmt"
"io"
)
// input -> gzip -> gowriter -> output.
func translate_memcpy_comp(input io.Reader, output io.Writer, pkgname, funcname, pathname string) {
fmt.Fprintf(output, `package %s
import (
"bytes"
"compress/gzip"
"io"
)
func init() {
EmbeddedFiles["%s"] = %s
}
// %s returns raw, uncompressed file data.
func %s() []byte {
gz, err := gzip.NewReader(bytes.NewBuffer([]byte{`, pkgname, pathname, funcname, funcname, funcname)
gz := gzip.NewWriter(&ByteWriter{Writer: output})
io.Copy(gz, input)
gz.Close()
fmt.Fprint(output, `
}))
if err != nil {
panic("Decompression failed: " + err.Error())
}
var b bytes.Buffer
io.Copy(&b, gz)
gz.Close()
return b.Bytes()
}`)
}