-
Notifications
You must be signed in to change notification settings - Fork 4
/
zipsave.ado
46 lines (37 loc) · 1.09 KB
/
zipsave.ado
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
43
44
45
46
program define zipsave
syntax anything [, replace ram *]
splitpath `anything'
local directory `r(directory)'
local filename `r(filename)'
local filetype `r(filetype)'
local files : dir "`directory'" files `"`filename'.zip"'
if "`files'"~="" & "`replace'"=="" {
display as error "file `anything' already exists"
exit 602
}
tempfile temp
splitpath `temp'
local tempdirectory `r(directory)'
if "`ram'"~=""{
qui memory
local sizem=`r(data_data_u)'/1000000
local ramsize = 2048*ceil(`sizem')
qui !hdiutil eject /Volumes/stataramdisk
qui !diskutil erasevolume HFS+ "stataramdisk" `hdiutil attach -nomount ram://`ramsize'`
*''
local tempdirectory "/Volumes/stataramdisk/"
}
else{
tempfile temp
splitpath `temp'
local tempdirectory `r(directory)'
}
qui !rm "`directory'/`filename'.zip"
qui save "`tempdirectory'`filename'.dta", replace
qui !cd "`tempdirectory'" && zip -o "`directory'`filename'.zip" "`filename'.dta" && rm "`filename'.dta"
qui !rm -r `tempdirectory'
if "`ram'"~=""{
qui !umount `tempdirectory'
qui !hdiutil eject `tempdirectory'
}
end