File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -3558,12 +3558,10 @@ Full list of builtin options:
3558
3558
#### $embed_file
3559
3559
3560
3560
``` v ignore
3561
- module main
3561
+ import os
3562
3562
fn main() {
3563
3563
embedded_file := $embed_file('v.png')
3564
- mut fw := os.create('exported.png') or { panic(err.msg) }
3565
- fw.write_bytes(embedded_file.data(), embedded_file.len)
3566
- fw.close()
3564
+ os.write_file('exported.png', embedded_file.to_string()) ?
3567
3565
}
3568
3566
```
3569
3567
Original file line number Diff line number Diff line change @@ -36,6 +36,22 @@ pub fn (mut ed EmbedFileData) free() {
36
36
}
37
37
}
38
38
39
+ pub fn (original &EmbedFileData) to_string () string {
40
+ unsafe {
41
+ mut ed := & EmbedFileData (original)
42
+ the_copy := memdup (ed.data (), ed.len)
43
+ return byteptr (the_copy).vstring_with_len (ed.len)
44
+ }
45
+ }
46
+
47
+ pub fn (original &EmbedFileData) to_bytes () []byte {
48
+ unsafe {
49
+ mut ed := & EmbedFileData (original)
50
+ the_copy := memdup (ed.data (), ed.len)
51
+ return the_copy.vbytes (ed.len)
52
+ }
53
+ }
54
+
39
55
pub fn (mut ed EmbedFileData) data () byteptr {
40
56
if ! isnil (ed.uncompressed) {
41
57
return ed.uncompressed
You can’t perform that action at this time.
0 commit comments