Created
October 31, 2016 08:50
-
-
Save bboozzoo/5e237dbada9b6dfe647f5d9f4408ba81 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Copyright 2016 Maciej Borzecki <[email protected]> | |
// | |
// Licensed under the Apache License, Version 2.0 (the "License"); | |
// you may not use this file except in compliance with the License. | |
// You may obtain a copy of the License at | |
// | |
// http://www.apache.org/licenses/LICENSE-2.0 | |
// | |
// Unless required by applicable law or agreed to in writing, software | |
// distributed under the License is distributed on an "AS IS" BASIS, | |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
// See the License for the specific language governing permissions and | |
// limitations under the License. | |
// | |
// Usage: | |
// | |
// ./progtest <file-path> | |
// curl -s <URL> | ./progtest | |
// | |
package main | |
import ( | |
"fmt" | |
"io" | |
"os" | |
"github.com/mendersoftware/mender/utils" | |
) | |
func main() { | |
f := os.Stdin | |
sz := int64(0) | |
if len(os.Args) == 2 { | |
userf, err := os.Open(os.Args[1]) | |
if err != nil { | |
panic(fmt.Errorf("open failed: %v", err)) | |
} | |
defer userf.Close() | |
fi, err := userf.Stat() | |
if err != nil { | |
panic(fmt.Errorf("stat failed: %v", err)) | |
} | |
sz = fi.Size() | |
f = userf | |
} | |
p := &utils.ProgressWriter{ | |
Out: os.Stderr, | |
N: sz, | |
} | |
if _, err := io.Copy(p, f); err != nil { | |
panic(fmt.Errorf("copy failed: %v", err)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment