MFile¶
MFile Framework 에 대한 필수 API 를 정의
File API¶
File IO 기능에 대한 API 를 제공
파일 생성¶
-
M.file.
create
(options)¶ Changed in version 2.2.0.
- Arguments
options (Object) – 설정 값
options.path (String) – 파일 및 폴더 경로
options.type (String) – 파일 및 폴더 여부 (FILE:파일 타입,DIR:폴더 타입)
File 및 directory를 생성한다.
- Surrogate Keys: 위 옵션키들과 같은 하위 버전 호환을 위한 대체 옵션 값들
name = path
alias = path
source = path
option = type
Example:
폴더 생성
var result = M.file.create({ 'type': 'DIR', 'path': 'doc://temp' }); console.log(result);
파일 생성
var result = M.file.create({ type: 'FILE', path: 'doc://temp/hello.txt' });
파일 읽기¶
-
M.file.
read
(setting)¶ Changed in version 2.2.0.
- Arguments
setting (Object) – 설정 값
setting.path (String) – 파일 및 폴더 경로
setting.encoding (String) – 파일 인코딩 (UTF-8, EUC-KR, BASE64)
setting.indicator (String) – 파일 로딩시 표시할 indicator의 message
setting.callback (function) –
파일 읽기 완료 후 callback 되는 함수
-
M.file.
callback
(result)¶ - Arguments
status (Object) – status 상태 코드 (SUCCESS:성공 코드, FAIL:실패 코드)
result (Object) – 파일 정보
result.message (String) – 메세지
result.size (int) – 파일 데이터 길이
result.data (String) – 파일의 text 데이터 (바이너리 파일의 경우 base64 데이터), 값이 [BLOB] 인 경우 읽을 수 없는 바이너리 파일
result.path (String) – 파일의 Scheme URL 경로
result.fullpath (String) – 파일의 전체 경로
-
- Surrogate Keys: 위 옵션키들과 같은 하위 버전 호환을 위한 대체 옵션 값들
name = path
alias = path
source = path
encode = encoding
load = callback
onload = callback
Example:
text 파일 읽기
M.file.read({ path: 'doc://temp/hello.txt', encoding: 'UTF-8', indicator: true, callback: function(status,result){ console.log(status + JSON.stringify(result)); } });
바이너리 파일 읽기
M.file.read({ path: '/storage/emulated/0/DCIM/Camera/sample_img.png', encoding: 'BASE64', indicator: true, callback: function(status,result){ console.log(status + JSON.stringify(result)); var imgView = document.getElementById('imageView'); //mime-type은 별도로 스크립트에서 지정 필요 imgView.src = "data:image/png;base64,"+result.data; } });
-
M.file.
read
(setting, callback)¶ Changed in version 2.2.0.
- Arguments
setting (Object) – 설정 값
setting.path (String) – 파일 및 폴더 경로
setting.encoding (String) – 파일 인코딩 (UTF-8, EUC-KR, BASE64)
setting.indicator (String) – 파일 로딩시 표시할 indicator의 message
callback (function) – 파일 읽기 완료 후 callback 되는 함수
File 의 Contents를 읽어 반환한다.
Example:
M.file.read({
path: 'doc://temp/hello.txt',
encoding: 'UTF-8',
indicator: true,
}, function(status,result){
console.log(status + JSON.stringify(result));
});
파일 삭제¶
-
M.file.
remove
(setting)¶ Changed in version 2.2.0.
- Arguments
setting (Object) – 설정 정보
setting.path (String) – 파일 및 폴더 경로
File 및 directory 를 삭제한다.
- Surrogate Keys: 위 옵션키들과 같은 하위 버전 호환을 위한 대체 옵션 값들
name = path
alias = path
source = path
option = type
Example:
폴더 삭제
var result = M.file.remove({ type: 'DIR', path: 'doc://temp/' }); M.tool.log(result); alert(JSON.stringify(result));
파일 삭제
var result = M.file.remove({ path: 'doc://temp/hello.txt' }); console.log(result);
파일 정보¶
-
M.file.
info
(setting)¶ Changed in version 2.2.0.
- Arguments
setting (Object) – 파일 정보
setting.path (String) – (source) 원본 경로
File 및 directory의 정보를 가져온다.
- Surrogate Keys: 위 옵션키들과 같은 하위 버전 호환을 위한 대체 옵션 값들
name = path
alias = path
source = path
Example:
var result = M.file.info({
path: 'doc://temp/'
});
console.log(result);
파일 정보 (목록)¶
-
M.file.
list
(setting)¶ Changed in version 2.2.0.
- Arguments
setting (Object) – 파일 정보
setting.path (String) – (source) 원본 경로
setting.filter (String) – 파일 및 폴더 여부 (FILE:파일 타입,DIR:폴더 타입)
File 및 directory의 정보를 가져온다.
- Surrogate Keys: 위 옵션키들과 같은 하위 버전 호환을 위한 대체 옵션 값들
name = path
alias = path
source = path
type = filter
Example:
var result = M.file.list({
path: 'doc://temp/',
filter: 'DIR'
});
console.log(result);
파일 복사¶
-
M.file.
copy
(setting)¶ Changed in version 2.2.0.
- Arguments
setting (Object) – 설정 정보
setting.type (String) – 파일 및 폴더 여부 (FILE:파일 타입,DIR:폴더 타입)
setting.source (String) – (source) 원본 경로
setting.destination (String) – (destination) 복사될 경로
setting.overwrite (boolean) – 덮어쓰기 여부
setting.indicator (String) – 파일 복사시 표시할 indicator 여부
setting.progress (function) –
파일 복사 중 진행 상태를 알려주는 함수
-
M.file.
progress
(total, current)¶ - Arguments
total (String) – 복사할 전체 파일 크기
current (String) – 복사된 파일 크기
-
setting.finish (function) –
파일 복사 완료 후 callback 되는 함수
-
finish
(status, result)¶ - Arguments
status (String) – status 상태 코드 (SUCCESS:성공 코드, FAIL:실패 코드}
result (String) – 복사된 파일 정보
result.message (String) – 메세지
result.size (int) – 파일 데이터 길이
result.data (String) – 파일의 text 데이터, 값이 [BLOB] 인 경우 바이너리 파일
result.path (String) – 파일의 Scheme URL 경로
result.fullpath (String) – 파일의 전체 경로
-
- Surrogate Keys: 위 옵션키들과 같은 하위 버전 호환을 위한 대체 옵션 값들
path = path
from = path
alias = path
source = path
to = destination
onprogress = progress
onfinish = finish
callback = finish
Example:
M.file.copy({
type: 'FILE',
source: 'doc://temp/hello.txt',
destination: 'doc://temp/hello1.txt',
indicator: true,
progress: function(total, current, setting){
console.log(total, current);
},
finish: function(result){
console.log(result);
}
});
-
M.file.
copy
(setting, callback)¶ Changed in version 2.2.0.
- Arguments
setting (Object) – 설정 정보
setting.type (String) – 파일 및 폴더 여부 (FILE:파일 타입,DIR:폴더 타입)
setting.source (String) – (source) 원본 경로
setting.destination (String) – (destination) 복사될 경로
setting.overwrite (boolean) – 덮어쓰기 여부
setting.indicator (String) – 파일 복사시 표시할 indicator 여부
setting.progress (function) –
파일 복사 중 진행 상태를 알려주는 함수
-
M.file.
progress
(total, current)¶ - Arguments
total (String) – 복사할 전체 파일 크기
current (String) – 복사된 파일 크기
-
callback (function) – 파일 복사 완료 후 callback 되는 함수
File 및 directory 를 복사한다.
Example:
M.file.copy({
type: 'FILE',
source: 'doc://temp/hello.txt',
destination: 'doc://temp/hello1.txt',
indicator: true,
progress: function(total, current, setting) {
console.log(total, current);
}
}, function(result) {
console.log(result);
});
파일 이동¶
-
M.file.
move
(setting)¶ Changed in version 2.2.0.
- Arguments
setting (Object) – 설정 정보
setting.type (String) – 파일 및 폴더 여부 (FILE:파일 타입,DIR:폴더 타입)
setting.source (String) – (source) 원본 경로
setting.destination (String) – (destination) 복사될 경로
setting.overwrite (boolean) – 덮어쓰기 여부
setting.indicator (String) – 파일 복사시 표시할 indicator 여부
setting.progress (function) –
파일 복사 중 진행 상태를 알려주는 함수
-
M.file.
progress
(total, current)¶ - Arguments
total (String) – 복사할 전체 파일 크기
current (String) – 복사된 파일 크기
-
setting.finish (function) –
파일 복사 완료 후 callback 되는 함수
-
finish
(status, result)¶ - Arguments
status (String) – status 상태 코드 (SUCCESS:성공 코드, FAIL:실패 코드}
result (String) – 복사된 파일 정보
result.message (String) – 메세지
result.size (int) – 파일 데이터 길이
result.data (String) – 파일의 text 데이터, 값이 [BLOB] 인 경우 바이너리 파일
result.path (String) – 파일의 Scheme URL 경로
result.fullpath (String) – 파일의 전체 경로
-
- Surrogate Keys: 위 옵션키들과 같은 하위 버전 호환을 위한 대체 옵션 값들
path = path
from = path
alias = path
source = path
to = destination
onprogress = progress
onfinish = finish
callback = finish
Example:
M.file.move({
type: 'FILE',
source: 'doc://temp/hello.txt',
destination: 'doc://temp/hello1.txt',
indicator: true,
progress: function(total, current, setting){
console.log(total, current);
},
finish: function(result){
console.log(result);
}
});
-
M.file.
move
(setting, callback)¶ Changed in version 2.2.0.
- Arguments
setting (Object) – 설정 정보
setting.type (String) – 파일 및 폴더 여부 (FILE:파일 타입,DIR:폴더 타입)
setting.source (String) – (source) 원본 경로
setting.destination (String) – (destination) 복사될 경로
setting.overwrite (boolean) – 덮어쓰기 여부
setting.indicator (String) – 파일 복사시 표시할 indicator 여부
setting.progress (function) –
파일 복사 중 진행 상태를 알려주는 함수
-
M.file.
progress
(total, current)¶ - Arguments
total (String) – 복사할 전체 파일 크기
current (String) – 복사된 파일 크기
-
callback (function) – 파일 복사 완료 후 callback 되는 함수
File 및 directory 를 이동한다.
Example:
M.file.move({
type: 'FILE',
source: 'doc://temp/hello.txt',
destination: 'doc://temp/hello1.txt',
indicator: true,
progress: function(total, current, setting) {
console.log(total, current);
}
}, function(result) {
console.log(result);
});
파일 쓰기¶
-
M.file.
write
(setting)¶ Changed in version 2.2.0.
- Arguments
setting (Object) – 설정 정보
setting.path (String) – 파일 및 폴더 경로
setting.contents (String) – 데이터
setting.encoding (String) – 파일 인코딩 (UTF-8, EUC-KR)
setting.indicator (String) – 파일 생성시 표시할 indicator
setting.callback (function) – 파일 쓰기 완료 후 callback 되는 함수
- Surrogate Keys: 위 옵션키들과 같은 하위 버전 호환을 위한 대체 옵션 값들
name = path
alias = path
source = path
data = contents
encode = encoding
finish = callback
onfinish = callback
Example:
M.file.write({
path: 'doc://temp/hello.txt',
contents: '안녕하세요.',
encoding: 'UTF-8',
callback: function(result){
console.log(result);
}
});
-
M.file.
write
(setting, callback)¶ Changed in version 2.2.0.
- Arguments
setting (Object) – 설정 정보
setting.path (String) – 파일 및 폴더 경로
setting.contents (String) – 데이터
setting.encoding (String) – 파일 인코딩 (UTF-8, EUC-KR)
setting.indicator (String) – 파일 생성시 표시할 indicator
callback (function) – 파일 쓰기 완료 후 callback 되는 함수
File에 Contents를 쓴다.
Example:
M.file.write({
path: 'doc://temp/hello.txt',
contents: '안녕하세요.',
encoding: 'UTF-8',
}, function(result) {
console.log(result);
});