|
1 | 1 | (ns sqlite.core |
2 | 2 | (:gen-class) |
3 | | - (:require |
4 | | - [clojure.java.io :as io])) |
| 3 | + (:require [clojure.java.io :as io])) |
5 | 4 |
|
6 | 5 | (defn lazy-byte-seq [filepath] |
7 | 6 | (let [is (io/input-stream filepath) |
8 | 7 | step (fn step [input-stream] |
9 | | - (lazy-seq |
10 | | - (let [byte-val (.read input-stream)] |
11 | | - (when (not= byte-val -1) |
12 | | - (cons byte-val (step input-stream))))))] |
| 8 | + (lazy-seq (let [byte-val (.read input-stream)] |
| 9 | + (when (not= byte-val -1) |
| 10 | + (cons byte-val (step input-stream))))))] |
13 | 11 | (step is))) |
14 | 12 |
|
15 | 13 | (defn bytes-to-int [bytes] |
16 | | - (reduce (fn [acc b] (+ (* acc 256) b)) 0 bytes)) |
| 14 | + (reduce (fn [acc b] (+ (* acc 256) b)) |
| 15 | + 0 |
| 16 | + bytes)) |
17 | 17 |
|
18 | 18 | (defn -main [& args] |
19 | | - ;; You can use print statements as follows for debugging, they'll be visible when running tests. |
| 19 | +;; You can use print statements as follows for debugging, they'll be |
| 20 | +;; visible when running tests. |
20 | 21 | (println "Logs from your program will appear here!") |
21 | | - |
22 | | - ;; Uncomment this block to pass the first stage |
23 | | - ;; (let [command (second args)] |
24 | | - ;; (case command |
25 | | - ;; ".dbinfo" |
26 | | - ;; (let [db-file-path (first args) |
27 | | - ;; contents (lazy-byte-seq db-file-path) |
28 | | - ;; page-size (bytes-to-int (take 2 (drop 16 contents)))] |
29 | | - ;; (println (str "database page size: " page-size))))) |
30 | | - ) |
| 22 | +;; Uncomment this block to pass the first stage |
| 23 | +;; (let [command (second args)] |
| 24 | +;; (case command |
| 25 | +;; ".dbinfo" |
| 26 | +;; (let [db-file-path (first args) |
| 27 | +;; contents (lazy-byte-seq db-file-path) |
| 28 | +;; page-size (bytes-to-int (take 2 (drop 16 contents)))] |
| 29 | +;; (println (str "database page size: " page-size))))) |
| 30 | +) |
0 commit comments