Skip to content

NodeJs module that takes either a web-url, filepath, or raw data and returns given data as a filepath, or raw data

Notifications You must be signed in to change notification settings

thnew/Filesource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

filesource.js

Install: npm install fileosurce

You can e.g. use it, if you want to offer a function, taking all possible types of data sources.

Here are some simple examples how to use it:

var filesource = require('filesource');

// Converts web-source to raw data
filesource.getRawData("http://blabla.com/blabla.pdf", function(resp){
	if(!resp.success)
	{
		console.log("Sth. went wrong: " + resp.error);
		return;
	}
	
	console.log(resp.data);	// raw data
});

// Converts filepath to raw data
filesource.getRawData("/files/example.pdf", function(resp){
	if(!resp.success)
	{
		console.log("Sth. went wrong: " + resp.error);
		return;
	}
	
	console.log(resp.data);	// raw data
});

// Converts web-source to readable filepath
filesource.getDataPath("http://blabla.com/blabla.pdf", function(resp){
	if(!resp.success)
	{
		console.log("Sth. went wrong: " + resp.error);
		return;
	}
	
	console.log(resp.data);	// local filepath
	
	resp.clean();
});

// Converts raw data to readable filepath
var rawData = fs.readFileSync("/files/example.pdf");

filesource.getDataPath(rawData, function(resp){
	if(!resp.success)
	{
		console.log("Sth. went wrong: " + resp.error);
		return;
	}
	
	console.log(resp.data);	// local filepath
	
	resp.clean();
});

About

NodeJs module that takes either a web-url, filepath, or raw data and returns given data as a filepath, or raw data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published