-
Notifications
You must be signed in to change notification settings - Fork 2
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 #5 from myjimnelson/0.4.1-branch
0.4.1 Release / cia3
- Loading branch information
Showing
27 changed files
with
2,899 additions
and
490 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package civ3decompress | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
// ReadFile takes a filename and returns the decompressed file data or the raw data if it's not compressed. Also returns true if compressed. | ||
func ReadFile(path string) ([]byte, bool, error) { | ||
// Open file, hanlde errors, defer close | ||
file, err := os.Open(path) | ||
if err != nil { | ||
return nil, false, FileError{err} | ||
} | ||
defer file.Close() | ||
|
||
var compressed bool | ||
var data []byte | ||
header := make([]byte, 2) | ||
_, err = file.Read(header) | ||
if err != nil { | ||
return nil, false, FileError{err} | ||
} | ||
// reset pointer to parse from beginning | ||
_, err = file.Seek(0, 0) | ||
if err != nil { | ||
return nil, false, FileError{err} | ||
} | ||
switch { | ||
case header[0] == 0x00 && (header[1] == 0x04 || header[1] == 0x05 || header[1] == 0x06): | ||
compressed = true | ||
data, err = Decompress(file) | ||
if err != nil { | ||
return nil, false, err | ||
} | ||
default: | ||
// Not a compressed file. Proceeding with uncompressed stream. | ||
data, err = ioutil.ReadFile(path) | ||
if err != nil { | ||
return nil, false, FileError{err} | ||
} | ||
} | ||
return data, compressed, error(nil) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.