Also preread STDIN when using /dev/stdin as the source
This commit is contained in:
parent
1cc69b3edd
commit
084671b26e
@ -17,7 +17,7 @@ import (
|
|||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
|
||||||
type Input struct {
|
type Input struct {
|
||||||
src *os.File
|
src io.Reader
|
||||||
arg string
|
arg string
|
||||||
ext string
|
ext string
|
||||||
is_stream bool
|
is_stream bool
|
||||||
@ -189,17 +189,28 @@ func run_set_loop(opts *Options, args []string) (err error) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
for _, i := range inputs {
|
for _, i := range inputs {
|
||||||
if i.src != nil {
|
if i.src != nil {
|
||||||
i.src.Close()
|
rc, ok := i.src.(io.Closer)
|
||||||
|
if ok {
|
||||||
|
rc.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for i, arg := range args {
|
for i, arg := range args {
|
||||||
|
if arg == "/dev/stdin" {
|
||||||
|
f, _, err := preread_stdin()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
inputs[i] = &Input{arg: arg, src: f, is_stream: true}
|
||||||
|
} else {
|
||||||
f, err := os.Open(arg)
|
f, err := os.Open(arg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to open %s with error: %w", arg, err)
|
return fmt.Errorf("Failed to open %s with error: %w", arg, err)
|
||||||
}
|
}
|
||||||
inputs[i] = &Input{arg: arg, src: f, ext: filepath.Ext(arg), is_stream: arg == "/dev/stdin"}
|
inputs[i] = &Input{arg: arg, src: f, ext: filepath.Ext(arg)}
|
||||||
|
}
|
||||||
if i < len(opts.Mime) {
|
if i < len(opts.Mime) {
|
||||||
inputs[i].mime_type = opts.Mime[i]
|
inputs[i].mime_type = opts.Mime[i]
|
||||||
} else if inputs[i].is_stream {
|
} else if inputs[i].is_stream {
|
||||||
@ -211,6 +222,8 @@ func run_set_loop(opts *Options, args []string) (err error) {
|
|||||||
return fmt.Errorf("Could not guess MIME type for %s use the --mime option to specify a MIME type", arg)
|
return fmt.Errorf("Could not guess MIME type for %s use the --mime option to specify a MIME type", arg)
|
||||||
}
|
}
|
||||||
to_process[i] = inputs[i]
|
to_process[i] = inputs[i]
|
||||||
|
if to_process[i].is_stream {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return write_loop(to_process, opts)
|
return write_loop(to_process, opts)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user