sitelink1 | http://nagoon97.wordpress.com/2008/04/06...sing-ajax/ |
---|---|
sitelink2 | http://www.heypage.com/nagoon97/BinFileR..._demo.html |
sitelink3 | |
sitelink4 | http://okjungsoo.tistory.com/7953804 |
extra_vars4 | |
extra_vars5 | |
extra_vars6 |
nagoon97님의 Reading binary files using Ajax 포스트에서는 Ajax를 이용하여 바이너리 파일에 접근하는 방법을 소개하고 있습니다.
- function BinFileReader(fileURL) {...} 을 호출합니다.
- 내부 변수들을 초기화 작업을 수행합니다.
- Browser의 userAgent를 체크하여서 IE인 경우에는 BinFileReaderImpl_IE를 호출하고 그 외의 경우에는 BinFileReaderImpl을 호출합니다.
- function BinFileReaderImpl(fileURL) {...} 에서는
- XMLHttpRequest를 생성한 다음에 mime type을 'text/plain; charset=x-user-defined' 설정한 다음에 file을 요청합니다.
req.overrideMimeType('text/plain; charset=x-user-defined'); - 성공적으로 로딩한 다음에는 fileContents에 responseText를 저장하고
- fileSize를 responseText.length를 저장합니다.
- 이 때 readByteAt(index) 메소드를 생성하는데 charCodeAt(index) & 0xff 값을 리턴합니다.
- XMLHttpRequest를 생성한 다음에 mime type을 'text/plain; charset=x-user-defined' 설정한 다음에 file을 요청합니다.
- function BinFileReaderImpl_IE(fileURL) {...}에서는 (VB코드로 구현)
- VB 코드를 사용하여 XMLHttp Request를 생성한 다음에
- 헤더에 "Accept-Charset", "x-user-defined"로 설정한 후 file을 요청합니다.
- file 로딩이 완료된 다음에는 responseBody를 통하여 byteArray를 얻어옵니다.
- 이 byteArray를 Array()로 변환한 다음에 fileSize를 생성 및 readByteAt()를 생성합니다.
제공되는 API는 다음과 같습니다.
- getFileSize() : 파일크기를 리턴
- getFilePointer() : 파일을 읽어들일 위치를 지정하는 내부 포인터의 값
- movePointerTo(iTo) : 포인터 위치 이동 (0 이상 fileSize 아래의 값으로 제한을 주는 것 외에는 값만 변경)
- movePointer(iDirection) : 읽어들이는 방향의 변경
- 그 외에 readNumber, readString, readUnicodeString을 사용하여 파일을 읽기 위해서 사용되는 메소드 제공