# dwca-reader

> A library that reads Darwin Core Archives with loading functions for mongo and elastic search.

Latest version **1.0.0** (published 2013-10-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install dwca-reader
pnpm add dwca-reader
yarn add dwca-reader
bun add dwca-reader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2013-10-28 |
| First published | 2013-10-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.6 |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | SilverBiology |
| Maintainers | jabrown |
| Keywords | dwca, dwc, darwin core, darwin core archive, gbif, idigbio |

## Links

- npm: https://www.npmjs.com/package/dwca-reader
- Repository: https://github.com/silverbiology/dwca-reader
- Issues: https://github.com/silverbiology/dwca-reader/issues
- npm.io page: https://npm.io/package/dwca-reader

## Dependencies (6)

- [csv](https://npm.io/package/csv.md) *
- [needle](https://npm.io/package/needle.md) *
- [adm-zip](https://npm.io/package/adm-zip.md) *
- [mongodb](https://npm.io/package/mongodb.md) *
- [node-xml2json](https://npm.io/package/node-xml2json.md) *
- [elasticsearchclient](https://npm.io/package/elasticsearchclient.md) *

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2013-10-28

## README

## dwca-reader Node.JS Library
===========
## Install

To install the most recent version, run 

```javascript
	npm install dwca-reader
```

## Introduction

This is a Node.JS library to read Darwin Core Archives and load into MongoDB, ElasticSearch, or custom stream.
The zip file must contain a meta.xml file, to give the information on the data to be read.
The following is a simple example of downloading a file and uploading it into mongo.

```javascript
  var dwcareader = require("../index.js");
  var dr = new dwcareader();

  // Download the following file, and send it to the next folder
  dr.getArchive('http://{path_to_archive}/{name}.zip', 
  'path', 
  null, 
  function(error, response, body) {
    if(error) {
      console.log(error, response);
	  }
  });
  
  /*
  Or, you can upload from an already downloaded .zip file
  dr.setArchive(path+'test.zip', function(error, msg){
    if(error) {
      console.log(msg);
    } else {
      console.log('setArchive worked!');
    }
  });
  */

  dr.transform = function(data) {
    /*
	  Write custom function to change bad data into better data
    */
    return data;
  }

  var config = {
    host: "host",
    port: "1000",
    db: "database",
    table: "table"
  };

  dr.import2mongo(config, function(err, res) {
	  if (err) {
	  	console.log("There was an error.");
	  } else {
	  	console.log("Total records read into the mongodb:", res.count);
      console.log("It took", res.read_time, "seconds to read the file(s).");
      console.log("It took a total of:", res.total_time, "seconds");
	  }
  });
```

## GitHub information

After cloning the repository, enter the repository and use 

```javascript
	npm install
```
  
The drivers should all install, and the library will be up and running.

## Examples

Inside the example folder, there are multiple examples to run to check that the code is working, and throwing errors correctly when not.
All of the examples require a local pathname, which is not set (it can be different for pc or mac).  This pathname must be set
in each example.
You can run the examples using 

```javascript
	node testname
```

The following are all of the examples at this point: 

  * archiveTest
  * elasticsearchTest
  * mongoTest

## Methods

The following are all of the functions that can be used for this library.  All options are JSON objects with specific fields to be declared.


### getArchive(url, destination, options, callback)

This function takes the url and downloads the file.  It downloads it into the destination path, and creates a new file using the
extension of the url. If a file with that name is already in the destination folder, the function assumes you do not want to download
the url and will exit this function.  If you want to download the file anyways, set the options.overwrite = true.
The callback only takes an error and msg variables, eg:
```javascript
  getArchive('http://{path_to_url}/{archive}.zip', 'localPath', {}, function(error, message) {}
```

### setArchive(location, callback)

This function takes a location of the files.  This is a simpler version of getArchive, and assumes the files are already downloaded.
The callback is the same as above, takes an error and msg variables.

### getSchema(callback)

This function is inheritly called in the readData function, so it never needs to be called. It accesses the meta.xml file. 
If the meta.xml is not found, it has a callback of the type function(err, schema).

### import2mongo(options, callback)

This function is used to send data from a url or file path into a specified mongo database.  The options variable must 
have the following variables:

  * `.host`
  * `.port`
  * `.db`
  * `.table`

If any of the above variables are not defined, the function will callback with an error and a message, same as above.
If the process completes, the callback gives out a (false, results), where the results has 3 fields:

  * `.count` This is the number of records that were read in from the file (rows in a .csv file).
  * `.read_time` This is the time it took to read the data from the file.
  * `.total_time` This is the total amount of time it took to read and write the data.

### import2elasticsearch(options, callback)

This function is used to send data from a url or file path into a specified elasticsearch index.  The options variable must 
have the following variables:

  * `.host`
  * `.port`
  * `.db` This is the index value in elasticsearch
  * `.table` This is the type name in elasticsearch

If any of the above variables are not defined, the function will callback with an error and a message, same as above.
If the process completes, the callback gives out a (false, results), where the results has 3 fields:

  * `.count` This is the number of records that were read in from the file (rows in a .csv file).
  * `.read_time` This is the time it took to read the data from the file.
  * `.total_time` This is the total amount of time it took to read and write the data.

---
_Source: https://npm.io/package/dwca-reader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
