-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from podtserkovskiy/compact_image_storage
compact_image_storage
- Loading branch information
Showing
14 changed files
with
609 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package compact | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
// kamikazeFile removes itself on Closing. | ||
type kamikazeFile struct { | ||
file *os.File | ||
} | ||
|
||
func (t *kamikazeFile) Seek(offset int64, whence int) (int64, error) { | ||
return t.file.Seek(offset, whence) | ||
} | ||
|
||
func newKamikazeFile() (*kamikazeFile, error) { | ||
file, err := ioutil.TempFile("", "") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &kamikazeFile{file: file}, nil | ||
} | ||
|
||
func (t *kamikazeFile) Write(p []byte) (n int, err error) { | ||
return t.file.Write(p) | ||
} | ||
|
||
func (t *kamikazeFile) Read(p []byte) (n int, err error) { | ||
return t.file.Read(p) | ||
} | ||
|
||
func (t *kamikazeFile) Close() error { | ||
closeErr := t.file.Close() | ||
removeErr := os.Remove(t.file.Name()) | ||
if closeErr != nil { | ||
return closeErr | ||
} | ||
if removeErr != nil { | ||
return closeErr | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.