cfunction (file/read f what &opt buf) Read a number of bytes from a file into a buffer. A buffer can be provided as an optional fourth argument, otherwise a new buffer is created. 'what' can either be an integer or a keyword. Returns the buffer with file contents. Values for 'what': :all - read the whole file :line - read up to and including the next newline character n (integer) - read up to n bytes from the file
(defn read-from-file [file-path] (let [f (file/open file-path :r) content (file/read f :all)] (file/close f) content)) ### USAGE (read-from-file "/path/to/file-read-example.janet") # => @"(defn read-from-file [file-path]\n (let [f (file/open file-path :r)\n content (file/read f :all)]\n (file/close f)\n content))\n"
#!/usr/bin/env janet # echo stdin to stdout. (file/write stdout (file/read stdin :all))