Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / redis / examples / file.js
1 // Read a file from disk, store it in Redis, then read it back from Redis.
2
3 var redis = require("redis"),
4     client = redis.createClient(),
5     fs = require("fs"),
6     filename = "kids_in_cart.jpg";
7
8 // Get the file I use for testing like this:
9 //    curl http://ranney.com/kids_in_cart.jpg -o kids_in_cart.jpg
10 // or just use your own file.
11
12 // Read a file from fs, store it in Redis, get it back from Redis, write it back to fs.
13 fs.readFile(filename, function (err, data) {
14     if (err) throw err
15     console.log("Read " + data.length + " bytes from filesystem.");
16     
17     client.set(filename, data, redis.print); // set entire file
18     client.get(filename, function (err, reply) { // get entire file
19         if (err) {
20             console.log("Get error: " + err);
21         } else {
22             fs.writeFile("duplicate_" + filename, reply, function (err) {
23                 if (err) {
24                     console.log("Error on write: " + err)
25                 } else {
26                     console.log("File written.");
27                 }
28                 client.end();
29             });
30         }
31     });
32 });