Skip to content

Instantly share code, notes, and snippets.

@nf
Forked from anonymous/cat.coffee
Created September 10, 2011 09:48
Show Gist options
  • Save nf/1208156 to your computer and use it in GitHub Desktop.
Save nf/1208156 to your computer and use it in GitHub Desktop.
Go and CoffeeScript examples of writing a file to stdout
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
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