Liking cljdoc? Tell your friends :D

clj-dbase.core

A small library to parse dbase files. Copyright (C) 2020 Henrik Jürges juerges.henrik@gmail.com

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

This module provides the utility to parse the dbase dbf table format into

The expected file format version is dBase v3. A dbf file starts with a variable header defining some metainformations and the field types and names. The remaining file is the record content.

Usage

The main entry point is the (parse-dbase-file input-file) function.

(def dbase-data (parse-dbase-file (clojure.java.io/file input-file)))

The returned data is a nested map of

{:header <meta informations>
 :fields <record field definitions>
 :records <the actual table data>}

Additionally, the field definition can be attatched to the record data.

(-> (java.io.file. input-file)
    (parse-dbase-file)
    (field-definition->records))

This results in the field name is also attached to the individual record for easier handling and post-processing.

A small library to parse dbase files.
Copyright (C) 2020  Henrik Jürges <juerges.henrik@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

This module provides the utility to parse the dbase dbf table format into

The expected file format version is dBase v3.
A dbf file starts with a variable header defining some metainformations
and the field types and names. The remaining file is the record content.

### Usage

The main entry point is the `(parse-dbase-file input-file)` function.

```
(def dbase-data (parse-dbase-file (clojure.java.io/file input-file)))
```

The returned data is a nested map of
```
{:header <meta informations>
 :fields <record field definitions>
 :records <the actual table data>}
```

Additionally, the field definition can be attatched to the record data.

```
(-> (java.io.file. input-file)
    (parse-dbase-file)
    (field-definition->records))
```
This results in the field name is also attached to the individual record
for easier handling and post-processing.
raw docstring

absclj

(abs n)
source

bytes->intclj

(bytes->int bytes)

Convert some bytes to an integer or uint32.

Convert some bytes to an integer or uint32.
sourceraw docstring

bytes->shortclj

(bytes->short bytes)

Converts some bytes to a short or uint16.

Converts some bytes to a short or uint16.
sourceraw docstring

calc-offsetclj

(calc-offset fields offset fs)

Calculate the offset after which the first record starts.

Calculate the `offset` after which the first record starts.
sourceraw docstring

enrich-recordclj

(enrich-record fields record)

Add the field definitions as keywords to some record.

Add the field definitions as keywords to some record.
sourceraw docstring

field-definition->recordsclj

(field-definition->records dbase-data)

Enrich the records with the field names as keywords.

Enrich the records with the field names as keywords.
sourceraw docstring

next-byte?clj

(next-byte? stream pred)

Test the next byte from the input stream with pred.

The stream is resetted afterwards.

Test the next byte from the input `stream` with `pred`.

The stream is resetted afterwards.
sourceraw docstring

parse-dbase-fieldsclj

(parse-dbase-fields stream)

Parse all fields in the header.

The parsing stops at the first carriage return, ascii code 13.

Parse all fields in the header.

The parsing stops at the first carriage return, ascii code 13.
sourceraw docstring

parse-dbase-fileclj

(parse-dbase-file file)

Take a dbase file and parse the file returnin a clojure map.

The consists of a :header part, the list of :fields definitions and the parsed :records data. At the moment only text and numbers are recognized as types.

Take a dbase `file` and parse the file returnin a clojure map.

The consists of a `:header` part, the list of `:fields` definitions
and the parsed `:records` data.
At the moment only text and numbers are recognized as types.
sourceraw docstring

parse-dbase-headerclj

(parse-dbase-header file)

Take a dbase file of version 3 and parse the metadata and field information.

Take a dbase `file` of version 3 and parse the metadata and field information.
sourceraw docstring

parse-dbase-metadataclj

(parse-dbase-metadata stream)

Parse the dbase header file from the input stream.

Parse the dbase header file from the input `stream`.
sourceraw docstring

parse-dbase-recordsclj

(parse-dbase-records file fields header)

Parse the num of records defined in header and with the defined fields order.

Parse the num of records defined in `header` and with the defined `fields` order.
sourceraw docstring

parse-fieldclj

(parse-field stream)

Parse a record field definition from the input stream.

The skipped bytes are reserved for internal field adress in memory or other file format version then 3.

Parse a record field definition from the input `stream`.

The skipped bytes are reserved for internal field adress in memory
or other file format version then 3.
sourceraw docstring

parse-field-nameclj

(parse-field-name stream)

Parse the field name from the input stream.

Parse the field name from the input `stream`.
sourceraw docstring

parse-last-update-timeclj

(parse-last-update-time stream)

Read the date from the input stream.

Read the date from the input `stream`.
sourceraw docstring

parse-record-fieldclj

(parse-record-field bytes field)

Converts the field into some appropriate clojure type.

The raw bytes of the record field. The header description of the field.

Converts the field into some appropriate clojure type.

The raw `bytes` of the record field.
The header description of the `field`.
sourceraw docstring

read-byteclj

(read-byte stream)
(read-byte stream n)

Read only one byte and optionaly skip n bytes

Read only one byte and optionaly skip `n` bytes
sourceraw docstring

read-bytesclj

(read-bytes stream n)
(read-bytes stream n m)

The main byte reading function.

Read from stream n bytes and optional skip m bytes.

The main byte reading function.

Read from `stream` n bytes and optional skip `m` bytes.
sourceraw docstring

type-fieldclj

(type-field field-type bytes)

Convert the bytes to the field-type mentioned in the field header.

Convert the bytes to the `field-type` mentioned in the field header.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close