Add ReadRomFile
This function combines ReadRomBlocks() and RomFromBlocks() into a single function. The other two functions still exist.
This commit is contained in:
parent
cc0e79c72b
commit
172e1211c5
|
|
@ -32,18 +32,7 @@ func main() {
|
|||
}
|
||||
|
||||
func run(args *Arguments) error {
|
||||
file, err := os.Open(args.Input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
blocks, err := fds.ReadRom(file, filepath.Ext(args.Input) == ".fds")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rom, err := fds.RomFromBlocks(filepath.Base(args.Input), blocks)
|
||||
rom, err := fds.ReadRomFile(args.Input, filepath.Ext(args.Input) == ".fds")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
19
reader.go
19
reader.go
|
|
@ -1,7 +1,7 @@
|
|||
package fds
|
||||
|
||||
import (
|
||||
//"os"
|
||||
"os"
|
||||
"fmt"
|
||||
"io"
|
||||
"bufio"
|
||||
|
|
@ -11,7 +11,22 @@ import (
|
|||
"github.com/sigurn/crc16"
|
||||
)
|
||||
|
||||
func ReadRom(r io.Reader, IsFds bool) ([]DiskBlock, error) {
|
||||
func ReadRomFile(filename string, IsFds bool) (*Rom, error) {
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
blocks, err := ReadRomBlocks(file, IsFds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return RomFromBlocks(filename, blocks)
|
||||
}
|
||||
|
||||
func ReadRomBlocks(r io.Reader, IsFds bool) ([]DiskBlock, error) {
|
||||
reader := bufio.NewReader(r)
|
||||
magic, err := reader.Peek(4)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue