1 | "use strict";
|
2 | var mime = require("mime-types"), fileExtension = require("file-extension"), node_path = require("path"), fs = require("fs");
|
3 | var File = (function () {
|
4 | |
5 |
|
6 |
|
7 |
|
8 |
|
9 | function File(e, path) {
|
10 | this.path = path;
|
11 | this.basename = node_path.basename(this.path);
|
12 | this.dirname = node_path.dirname(this.path);
|
13 |
|
14 | this.getStatistics();
|
15 | }
|
16 | |
17 |
|
18 |
|
19 | File.prototype.getStatistics = function () {
|
20 | this.contentType = mime.lookup(this.getPath());
|
21 | this.extension = fileExtension(this.getPath());
|
22 | };
|
23 | |
24 |
|
25 |
|
26 |
|
27 | File.prototype.getName = function () {
|
28 | return this.basename;
|
29 | };
|
30 | |
31 |
|
32 |
|
33 |
|
34 | File.prototype.setName = function (filename) {
|
35 | this.basename = filename;
|
36 | };
|
37 | |
38 |
|
39 |
|
40 |
|
41 | File.prototype.getNameProper = function () {
|
42 | return node_path.basename(this.getBasename(), node_path.extname(this.getBasename()));
|
43 | };
|
44 | |
45 |
|
46 |
|
47 |
|
48 | File.prototype.getDirname = function () {
|
49 | return this.dirname;
|
50 | };
|
51 | |
52 |
|
53 |
|
54 |
|
55 | File.prototype.getPath = function () {
|
56 | return this.path;
|
57 | };
|
58 | |
59 |
|
60 |
|
61 |
|
62 | File.prototype.setPath = function (path) {
|
63 | this.path = path;
|
64 | };
|
65 | |
66 |
|
67 |
|
68 |
|
69 | File.prototype.getContentType = function () {
|
70 | return this.contentType;
|
71 | };
|
72 | |
73 |
|
74 |
|
75 |
|
76 | File.prototype.getExtension = function () {
|
77 | return this.extension;
|
78 | };
|
79 | |
80 |
|
81 |
|
82 |
|
83 | File.prototype.getBasename = function () {
|
84 | return this.basename;
|
85 | };
|
86 | |
87 |
|
88 |
|
89 | File.prototype.renameLocal = function () {
|
90 | var new_path = this.getDirname() + node_path.sep + this.getName();
|
91 | fs.renameSync(this.getPath(), new_path);
|
92 | this.setPath(new_path);
|
93 | this.getStatistics();
|
94 | };
|
95 | return File;
|
96 | }());
|
97 | exports.File = File;
|