Skip to content

Commit 306d097

Browse files
author
doubleface
committedApr 6, 2017
Now stubs the cozy.files api
1 parent 5042e62 commit 306d097

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
 

‎.editorconfig

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# editorconfig.org
2+
# editorconfig is a unified configuration file that all editors can take
3+
# into account
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
indent_style = space
12+
indent_size = 2
13+
14+
[*.coffee]
15+
indent_size = 4
16+
17+
[*.jade]
18+
trim_trailing_whitespace = false
19+
20+
[*.pug]
21+
trim_trailing_whitespace = false
22+
23+
[*.styl]
24+
indent_size = 4

‎cozy-client-js-stub.js

+44
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,49 @@ module.exports = {
3333
delete () {
3434
return Promise.resolve({})
3535
}
36+
},
37+
files: {
38+
statByPath (pathToCheck) {
39+
// check this path in ./data
40+
return new Promise((resolve, reject) => {
41+
log(`Checking if ${pathToCheck} exists`)
42+
const realpath = path.join('./data', pathToCheck)
43+
log(`Real path : ${realpath}`)
44+
if (fs.existsSync(realpath)) {
45+
resolve({_id: pathToCheck})
46+
} else {
47+
reject(new Error(`${pathToCheck} does not exist`))
48+
}
49+
})
50+
},
51+
create (file, options) {
52+
return new Promise((resolve, reject) => {
53+
log(`Creating new file ${options.name}`)
54+
const finalPath = path.join('./data', options.dirID, options.name)
55+
log(`Real path : ${finalPath}`)
56+
let writeStream = fs.createWriteStream(finalPath)
57+
file.pipe(writeStream)
58+
59+
file.on('end', () => {
60+
log(`File ${finalPath} created`)
61+
resolve()
62+
})
63+
64+
writeStream.on('error', err => {
65+
log(`Error : ${err}`)
66+
reject(new Error(err))
67+
})
68+
})
69+
},
70+
createDirectory (options) {
71+
return new Promise((resolve, reject) => {
72+
log(`Creating new directory ${options.name}`)
73+
const finalPath = path.join('./data', options.dirID, options.name)
74+
log(`Real path : ${finalPath}`)
75+
let result = fs.mkdir(finalPath)
76+
if (result) resolve()
77+
else reject(new Error(`Could not create ${finalPath}`))
78+
})
79+
}
3680
}
3781
}

0 commit comments

Comments
 (0)
Please sign in to comment.