Skip to content

Commit

Permalink
ioutilx: Add ioutilx package.
Browse files Browse the repository at this point in the history
  • Loading branch information
mewmew committed Apr 17, 2016
1 parent b3f622c commit a718148
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
@@ -1,4 +1,6 @@
language: go
go:
- 1.6

notifications:
email: false
Expand All @@ -11,7 +13,6 @@ env:
before_install:
- go get golang.org/x/tools/cmd/cover
- go get golang.org/x/tools/cmd/goimports
- go get golang.org/x/tools/cmd/vet
- go get github.com/golang/lint/golint
- go get github.com/mattn/goveralls

Expand Down
22 changes: 3 additions & 19 deletions README.md
@@ -1,29 +1,11 @@
# pkg

[![Build Status](https://travis-ci.org/mewkiz/pkg.svg?branch=master)](https://travis-ci.org/mewkiz/pkg)
[![Coverage Status](https://img.shields.io/coveralls/mewkiz/pkg.svg)](https://coveralls.io/r/mewkiz/pkg?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/mewkiz/pkg/badge.svg?branch=master)](https://coveralls.io/github/mewkiz/pkg?branch=master)
[![GoDoc](https://godoc.org/github.com/mewkiz/pkg?status.svg)](https://godoc.org/github.com/mewkiz/pkg)

The pkg project provides packages for various utility functions and commonly used features.

## Mature packages

Packages which reach a certain level of maturity are moved to dedicated repositories under the [mewpkg] organization. This enables API stability through the use of [Semantic Versioning](http://semver.org/).

[mewpkg]: https://github.com/mewpkg/

The following packages have been moved:

- [bits]: provides bit reading operations and binary decoding algorithms.
- [hashutil]: provides utility interfaces for hash functions.
- [crc8][hashutil/crc8]: implements the 8-bit cyclic redundancy check, or CRC-8, checksum.
- [crc16][hashutil/crc16]: implements the 16-bit cyclic redundancy check, or CRC-16, checksum.

[bits]: http://godoc.org/github.com/mewpkg/bits
[hashutil]: http://godoc.org/github.com/mewpkg/hashutil
[hashutil/crc8]: http://godoc.org/github.com/mewpkg/hashutil/crc8
[hashutil/crc16]: http://godoc.org/github.com/mewpkg/hashutil/crc16

## Documentation

Documentation provided by GoDoc.
Expand All @@ -38,6 +20,7 @@ Documentation provided by GoDoc.
- [htmlutil]: implements some html utility functions.
- [httputil]: implements some http utility functions.
- [imgutil]: implements some image utility functions.
- [ioutilx]: implements extended input/output utility functions.
- [osutil]: implements some os utility functions.
- [pathutil]: implements path utility functions.
- [proxy]: provides proxy server utility functions.
Expand All @@ -55,6 +38,7 @@ Documentation provided by GoDoc.
[htmlutil]: http://godoc.org/github.com/mewkiz/pkg/htmlutil
[httputil]: http://godoc.org/github.com/mewkiz/pkg/httputil
[imgutil]: http://godoc.org/github.com/mewkiz/pkg/imgutil
[ioutilx]: http://godoc.org/github.com/mewkiz/pkg/ioutilx
[osutil]: http://godoc.org/github.com/mewkiz/pkg/osutil
[pathutil]: http://godoc.org/github.com/mewkiz/pkg/pathutil
[proxy]: http://godoc.org/github.com/mewkiz/pkg/proxy
Expand Down
27 changes: 27 additions & 0 deletions ioutilx/ioutilx.go
@@ -0,0 +1,27 @@
// Package ioutilx implements extended input/output utility functions.
package ioutilx

import (
"io/ioutil"
"os"

"github.com/mewkiz/pkg/errutil"
)

// ReadFile reads from the given file, or standard input if path is "-", and
// returns its file contents.
func ReadFile(path string) ([]byte, error) {
if path == "-" {
// Read from standard input.
buf, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return nil, errutil.Err(err)
}
return buf, nil
}
buf, err := ioutil.ReadFile(path)
if err != nil {
return nil, errutil.Err(err)
}
return buf, nil
}

0 comments on commit a718148

Please sign in to comment.