Created
November 13, 2011 17:13
-
-
Save anonymous/1362348 to your computer and use it in GitHub Desktop.
This file contains 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
(ns mytest3) | |
(def file-path "/Users/me/Desktop/temp/bob.txt") | |
;(def file-path "/Users/me/Downloads/3MB-file.m4a") | |
(def group-by-twos | |
(fn [a-list] | |
(let [first-two (fn [a-list] (list (take 2 a-list))) | |
the-rest-after-two (fn [a-list] (rest (rest a-list))) | |
only-two-left? (fn [a-list] (if (= (count a-list) 2) true false))] | |
(loop [result '() rest-of-list a-list] | |
(if (empty? rest-of-list) | |
result | |
(recur (doall (concat result (first-two rest-of-list))) | |
(doall (the-rest-after-two rest-of-list)))))))) | |
(def get-the-file | |
(fn [file-name-and-path] | |
(let [the-file-pointer | |
(new java.io.RandomAccessFile (new java.io.File file-name-and-path) "r") | |
intermediate-array (byte-array (.length the-file-pointer))] ;reserve space for final length | |
(.readFully the-file-pointer intermediate-array) | |
(partition 2 (seq intermediate-array))))) | |
;(group-by-twos (seq intermediate-array))))) | |
(spit "bob2.txt" (some-pretty-print-here (get-the-file file-path))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment