-
-
Save nf/1208156 to your computer and use it in GitHub Desktop.
Go and CoffeeScript examples of writing a file to stdout
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
fs = require 'fs' | |
class File | |
constructor: (@name) -> | |
read: (cb) -> | |
fs.readFile @name, (err, code) -> | |
throw err if err | |
cb code.toString() | |
file = new File "file.txt" | |
file.read (contents) -> | |
console.log contents |
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
package main | |
import ( | |
"io" | |
"log" | |
"os" | |
) | |
func cat(name string) os.Error { | |
f, err := os.Open(name) | |
if err != nil { | |
return err | |
} | |
defer f.Close() | |
if _, err = io.Copy(os.Stdout, f); err != nil { | |
return err | |
} | |
return nil | |
} | |
func main() { | |
for _, arg := range os.Args[1:] { | |
if err := cat(arg); err != nil { | |
log.Print(err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment