통신 Javascript 를 사용하여 Binary File 읽기

황제낙엽 2010.09.29 12:53 조회 수 : 499 추천:55

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를 이용하여 바이너리 파일에 접근하는 방법을 소개하고 있습니다. 

  1. function BinFileReader(fileURL) {...} 을 호출합니다.
  2. 내부 변수들을 초기화 작업을 수행합니다.
  3. Browser의 userAgent를 체크하여서 IE인 경우에는 BinFileReaderImpl_IE를 호출하고 그 외의 경우에는 BinFileReaderImpl을 호출합니다.
  4. function BinFileReaderImpl(fileURL) {...} 에서는
    1. XMLHttpRequest를 생성한 다음에 mime type을 'text/plain; charset=x-user-defined' 설정한 다음에 file을 요청합니다.
      req.overrideMimeType('text/plain; charset=x-user-defined');

    2. 성공적으로 로딩한 다음에는 fileContents에 responseText를 저장하고
    3. fileSize를 responseText.length를 저장합니다.
    4. 이 때 readByteAt(index) 메소드를 생성하는데 charCodeAt(index) & 0xff 값을 리턴합니다.

  5. function BinFileReaderImpl_IE(fileURL) {...}에서는 (VB코드로 구현)
    1. VB 코드를 사용하여 XMLHttp Request를 생성한 다음에
    2. 헤더에 "Accept-Charset", "x-user-defined"로 설정한 후 file을 요청합니다.
    3. file 로딩이 완료된 다음에는 responseBody를 통하여 byteArray를 얻어옵니다.
    4. 이 byteArray를 Array()로 변환한 다음에 fileSize를 생성 및 readByteAt()를 생성합니다.
내부에는 filePointer (private)변수를 가지고 있어서 readString()을 호출하여 읽어들이는 경우 해당하는 읽어들이는 위치로 파일 포인터(위에서 얻어온 Array 또는 String에 접근하기 위한 index)를 변경 시킨 다음에 읽어들이게 됩니다.

제공되는 API는 다음과 같습니다.
  1. getFileSize() : 파일크기를 리턴
  2. getFilePointer() : 파일을 읽어들일 위치를 지정하는 내부 포인터의 값
  3. movePointerTo(iTo) : 포인터 위치 이동 (0 이상 fileSize 아래의 값으로 제한을 주는 것 외에는 값만 변경)
  4. movePointer(iDirection) : 읽어들이는 방향의 변경
  5. 그 외에 readNumber, readString, readUnicodeString을 사용하여 파일을 읽기 위해서 사용되는 메소드 제공
제공되는 예제에 BMP 파일의 헤더를 직접 읽어들여서 width/height/bits per pixel 값과 fileSize를 읽어들이는 것을 보실 수도 있습니다.
번호 제목 글쓴이 날짜 조회 수
117 Defining classes and inheritance (클래스 정의와 상속) 황제낙엽 2011.03.24 392
116 User Agent 관련 Reference URL 황제낙엽 2011.02.22 41
115 각 브라우저 별 User Agent 정보 황제낙엽 2011.02.22 823
114 History of User Agent 황제낙엽 2011.02.22 38
113 Navigator 객체란? 황제낙엽 2011.02.22 53
112 Understanding User-Agent Strings 황제낙엽 2011.02.22 76
111 User Agent 정보 모음 file 황제낙엽 2011.02.22 7767
110 ActiveX 설치 여부를 검사하는 스크립트 황제낙엽 2011.02.13 4052
109 [JavaScript Tutorials] Error handling in JavaScript using try/catch/finally - The Error object and throwing your own errors (해석중) 황제낙엽 2009.04.10 82
108 [JavaScript Tutorials] More leakage patterns (해석중) 황제낙엽 2009.04.10 142
107 [JavaScript Tutorials] Introducing the closure (해석중) 황제낙엽 2009.04.10 555
106 [JavaScript Tutorials] JavaScript and memory leaks (해석중) 황제낙엽 2009.04.08 102
105 [JavaScript Tutorials] Handling runtime errors in JavaScript using try/catch/finally (해석중) 황제낙엽 2009.04.08 2784
104 JavaScript Closures for Dummies 황제낙엽 2009.04.08 227
103 자바스크립트 예약어 황제낙엽 2010.11.03 35
102 YUI Logger(Yahoo) 를 동적으로 로드하는 북마크릿 황제낙엽 2010.10.03 25
» Javascript 를 사용하여 Binary File 읽기 황제낙엽 2010.09.29 499
100 크로스 브라우저를 위한 브라우저 검사 코드 file 황제낙엽 2010.08.27 86
99 Dynatrace For Ajax Performance 황제낙엽 2010.08.18 45
98 javascirpt IME-Mode 설정하기 황제낙엽 2010.08.17 1112