SeaWeedFs Nodejs Client
A seaweedfs client that is stable and resilient. You most likely will never lose a write or a read.
Install
npm install seaweedfs --save
The SeaweedFS class allows you to make calls like write, find, read, remove, clusterStatus
SeaweedFS = require'seaweedfs'ws = wsconnectthen -> clusterStatusthen consolelog status wswrite'This is some text'then wsfind'1,00032423af'then consolelog locations wsread'1,00032423af'then consolelog raw_data wsremove'1,00032423af'then consolelog responsecatch consolelog err
Documentation
You can initiate a client by default it connects to 1 master
SeaweedFS = require'seaweedfs'ws = # These are the default options masters: # The list of masters the client could connect to it host: 'localhost' port: 9333 scheme: 'http' # Whether http or https retry_count: 60 # This is the no of times a request is retried until it fails retry_timeout: 2000 #ms # This is used to retry any request that fails within the timeout All these methods return a bluebird Promise. All these methods return the request data only when full_response is false but return headers, status, body of the response when full_response is true. log_name: 'SeaweedFS' log_level: 'info';
Methods
All these methods return a bluebird Promise
clusterStatus()
This function will query the master status for status information. The callback contains an object containing the information.
client;
write(file)
Use this to store files
client;
You can also write multiple files:
client;
find(fid)
This function can be used to find the locations of a file in the cluster.
client;
read(fid, stream=null)
The read function supports streaming. To use simply do:
client;
If you prefer not to use streams just use:
client;
remove(fid)
This function will delete a file from the store. It will be deleted from all locations.
client;
Error Handling
Any Call to the client can result in an error you can just catch the error and do what you need to do then
Here is a list of errors that it can throw,
"file '#{file_id}' not found""Failed request to #{uri}""Unable to perform file operations on '#{file_id}': #{JSON.stringify(errors)}""File location for '#{file_id}' not found""File '#{file_id}' is not a valid file_id""An error occured while upload files: #{JSON.stringify(results)}"'Could not connect to any nodes'
License
Playlyfe Weedfs Node Client v1.0.0
http://dev.playlyfe.com/
Copyright(c) 2013-2015, Playlyfe IT Solutions Pvt. Ltd, support@playlyfe.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.