2012-09-26 3 views
2

Amazon S3 API for Ruby는 블록을 읽기 메소드로 전달할 때 객체를 스트리밍합니다. em-ftpd 용 드라이버를 개발 중이고 S3 데이터를 클라이언트로 스트리밍하기 위해 IOish 객체가 필요합니다. 단순히 myS3Object.read를 전달하면 S3 API에서 설명한대로 전체 파일이 메모리에로드됩니다. 스트림을 em-ftpd에 전달할 수 있도록 사용자 정의 IO 클래스와 같은 것으로 캡슐화하는 방법이 있습니까?S3 객체의 다운로드 스트림을 가져 와서 루비의 다른 메소드로 전달

: 여기
def get_file(path) 
    #loading whole file into memory - not efficient 
    yield bucket.objects[path].read 
end 

는 데이터 조각을 얻을 수있는 블록을 이용하여, 바람직 IOish 객체로서, 내 코드의 결과를 가져 EM-FTPD 내부 코드이다 : 여기

내 코드
# send a file to the client 
def cmd_retr(param) 
    send_unauthorised and return unless logged_in? 
    send_param_required and return if param.nil? 

    path = build_path(param) 

    @driver.get_file(path) do |data| 
    if data 
     send_response "150 Data transfer starting #{data.size} bytes" 
     send_outofband_data(data) 
    else 
     send_response "551 file not available" 
    end 
    end 
end 

고맙습니다.

답변

0

S3 데이터와 읽기 및 eof 메서드의 버퍼를 사용하여 클래스를 만들어야한다는 것을 알게되었습니다.

관련 문제