Socket
Book a DemoInstallSign in
Socket

anyfetch-file-hydrater

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anyfetch-file-hydrater

Create file hydrater for AnyFetch.

Source
npmnpm
Version
0.2.12
Version published
Weekly downloads
1
Maintainers
2
Weekly downloads
 
Created
Source

AnyFetch file hydrater

Build StatusDependency Status Coverage Status NPM version

Base library for file hydration on http://anyfetch.com.

Using this library requires a single function which takes a file path and metadatas, and returns more metadatas.

How to use?

'use strict';

var anyfetchFileHydrater = require('anyfetch-file-hydrater');

/**
 * Hydration function, to add metadatas to the document
 * 
 * @param{Object} filePath Path to the file to hydrate, downloaded for you on the filesystem
 * @param {Object} document Metadatas currently known (from previous hydraters, or from providers). Includes `document_type`, and `metadatas`.
 */
var myHydrationFunction = function(filePath, document, cb) {
  // Do stuff with the file...
  // Improve document...

  cb(err, document);
};

var config = {
  'hydrater_function': myHydrationFunction
};

var hydrationServer = anyfetchFileHydrater.createServer(config);
hydrationServer.listen(8000);

Now you're all done! Your server is running on port 8000. Access /hydrate with a standard AnyFetch POST request, and start hydrating your file.

POST <your_url>/hydrate
  file_path: <url-file-to-hydrate>
  callback: <url-to-ping>
  document: {base document}

In some cases, you may want to override the lib and send the result yourself. To do so, you can use cb.callbackUrl to send datas back to the client, and then call cb() without any error or document to finalize hydration, clean the file and start another task.

Optional parameters

createServer() takes an object hash for argument. hydrater_function is mandatory, optional values includes:

  • concurrency, max number of simultaneous calls to your hydrater function (default: 1)
  • logger function to use for logging error and success. Will get notified with strings when a task is started or ended. When an error occured, you'll get the path of the file, and the err as second argument.and not thrown).

Keywords

anyfetch

FAQs

Package last updated on 27 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts