-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileShell.coffee
42 lines (32 loc) · 1.04 KB
/
fileShell.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# @ts-check
import $replace from './replace'
import $noop from './noop'
class FileShell
###* @type import('../type/fileShell').Constructor ###
constructor: (source) ->
###* @type import('../type/fileShell').FileShell['source'] ###
@source = source
###* @type import('../type/fileShell').FileShell['append'] ###
append: (content) ->
$noop content
Native 'FileAppend, % content, % this.source, UTF-8'
return
###* @type import('../type/fileShell').FileShell['isExists'] ###
isExists: -> FileExist @source
###* @type import('../type/fileShell').FileShell['read'] ###
read: ->
unless @isExists() then return ''
$result = ''
Native 'FileRead, $result, % this.source'
return $replace $result, '\r', ''
###* @type import('../type/fileShell').FileShell['remove'] ###
remove: ->
unless @isExists() then return
Native 'FileDelete, % this.source'
return
###* @type import('../type/fileShell').FileShell['write'] ###
write: (content) ->
@remove()
@append content
return
$noop FileShell