클래스: Mongo::Grid::FSBucket::Stream::Write

상속:
객체
  • 객체
모두 표시
다음에 정의됨:
lib/ Mongo/grid/ 스트림/ 쓰기 (write).rb

개요

FSBucket에 파일을 쓰는 스트림 입니다.

이후:

  • 2.1.0

인스턴스 속성 요약 접기

인스턴스 메서드 요약 접기

생성자 세부 정보

#initialize(fs, options) ⇒ 쓰기

FSBucket에 파일을 쓰기 위한 스트림을 만듭니다.

예시:

스트림을 생성합니다.

Stream::Write.new(fs, options)

매개변수:

  • fs (FSBucket)

    GridFS 버킷 객체입니다.

  • 옵션 (해시)

    쓰기 (write) 스트림 옵션입니다.

  • opts (해시)

    사용자 지정 가능한 옵션 세트

옵션 해시(options):

  • :file_id (객체)

    파일 ID입니다. 파일 ID를 제공하지 않으면 ObjectId가 생성됩니다.

  • :write (해시)

    더 이상 사용되지 않습니다. :write_concern 옵션과 동일합니다.

  • :write_concern (해시)

    쓰기 고려 (write concern) 옵션. :w => Integer|String, : fsync => Boolean, :j => Boolean일 수 있습니다.

이후:

  • 2.1.0



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 파일 'lib/ Mongo/grid/ 스트림/ 쓰기 (write).rb', 줄 70

def 초기화(fs, 옵션)
  @fs = fs
  @Length = 0
  @n = 0
  @file_id = 옵션[:file_id] || BSON::ObjectId.신규
  @options = 옵션.dup
=begin WriteConcern 객체 지원
  if @options[:write_concern].is_a?(WriteConcern::Base)
    # 인스턴스를 캐시하여 불필요하게 재구성하지 않도록 합니다.
    @write_concern = @options[:write_concern]
    @options[:write_concern] = @write_concern.options
  end
=end
  @options.동결
  @filename = @options[:filename]
  @open = true
  @timeout_holder = CsotTimeoutHolder.신규(
    operation_timeout: {
      operation_timeout_ms: 옵션[:timeout_ms],
      inherited_timeout_ms: fs.database.timeout_ms
    }
  )
end

인스턴스 속성 세부 정보

#file_id객체 (읽기 전용)

반환값 file_id 업로드 중인 파일의 ID입니다.

반환합니다:

  • (객체)

    file_id 업로드되는 파일의 ID입니다.

이후:

  • 2.1.0



36
37
38
# 파일 'lib/ Mongo/grid/ 스트림/ 쓰기 (write).rb', 줄 36

def file_id
  @file_id
end

#파일 이름string (읽기 전용)

파일 이름을 반환합니다. 업로드 중인 파일 의 이름입니다.

반환합니다:

  • (string)

    파일명 업로드되는 파일의 이름입니다.

이후:

  • 2.1.0



41
42
43
# 파일 'lib/ Mongo/grid/ 스트림/ 쓰기 (write).rb', 줄 41

def 파일 이름
  @filename
end

#fsFSBucket (읽기 전용)

반환값 fs 이 스트림 이 기록하는 fs 버킷입니다.

반환합니다:

  • (FSBucket)

    fs 이 스트림이 기록하는 fs 버킷입니다.

이후:

  • 2.1.0



31
32
33
# 파일 'lib/ Mongo/grid/ 스트림/ 쓰기 (write).rb', 줄 31

def fs
  @fs
end

#options해시 (읽기 전용)

반환값 옵션 쓰기 스트림 옵션입니다.

반환합니다:

  • (해시)

    options 쓰기 스트림 옵션입니다.

이후:

  • 2.1.0



46
47
48
# 파일 'lib/ Mongo/grid/ 스트림/ 쓰기 (write).rb', 줄 46

def 옵션
  @options
end

인스턴스 메서드 세부 정보

#중단true

이미 삽입된 모든 청크를 삭제하여 업로드를 중단합니다.

예시:

쓰기 작업을 중단합니다.

stream.abort

반환합니다:

  • (true)

    작업이 중단되고 스트림 이 닫히면 참입니다.

이후:

  • 2.1.0



182
183
184
185
186
187
188
# 파일 'lib/ Mongo/grid/ 스트림/ 쓰기 (write).rb', 줄 182

def 중단
  fs.chunks_collection.찾기(
    { :files_id => file_id },
    @options.merge(timeout_ms: @timeout_holder.잔여 시간 초과_ms!)
  ).delete_many
  (@open = 거짓) || true
end

#닫기BSON::ObjectId, 객체

쓰기 스트림을 닫습니다.

예시:

스트림을 닫습니다.

stream.close

반환합니다:

  • (BSON::ObjectId, Object)

    파일 ID입니다.

다음을 발생시킵니다.

이후:

  • 2.1.0



135
136
137
138
139
140
141
142
143
144
# 파일 'lib/ Mongo/grid/ 스트림/ 쓰기 (write).rb', 줄 135

def 닫기
  sure_open!
  update_Length
  파일 컬렉션.insert_one(
    file_info,
    @options.merge(timeout_ms: @timeout_holder.잔여 시간 초과_ms!)
  )
  @open = 거짓
  file_id
end

#닫았나요?true, false

스트림이 닫혀 있나요?

예시:

스트림이 닫혀 있나요?

stream.closed?

반환합니다:

  • (true, false)

    스트림이 닫혔는지 여부입니다.

이후:

  • 2.1.0



170
171
172
# 파일 'lib/ Mongo/grid/ 스트림/ 쓰기 (write).rb', 줄 170

def 닫힘?
  !@open
end

#write(io) ⇒ Stream::Write

소스 스트림 또는 string 에서 GridFS 버킷에 씁니다.

예시:

GridFS 에 쓰기.

stream.write(io)

매개변수:

  • io (string | IO)

    업로드할 string 또는 IO 객체입니다.

반환합니다:

  • (Stream::Write)

    self 쓰기 (write) 스트림 자체입니다.

이후:

  • 2.1.0



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# 파일 'lib/ Mongo/grid/ 스트림/ 쓰기 (write).rb', 줄 104

def 쓰기(io)
  sure_open!
  @indexes ||= ensure_indexes!
  @Length += 만약 io.response_to?(:bytesize)
    # string 객체
    io.bytesize
  other
    # IO 객체
    io.size
  end
  청크 = file::청크.split(io, file_info, @n)
  @n += 청크.size
  하지 않는 한 청크.비어 있나요?
    chunks_collection.insert_many(
      청크,
      timeout_ms: @timeout_holder.잔여 시간 초과_ms!
    )
  end
  self
end

#write_concernMongo::WriteConcern

업로드 시 사용되는 쓰기 고려 (write concern) 를 가져옵니다.

예시:

쓰기 고려 (write concern) 를 가져옵니다.

stream.write_concern

반환합니다:

이후:

  • 2.1.0



154
155
156
157
158
159
160
# 파일 'lib/ Mongo/grid/ 스트림/ 쓰기 (write).rb', 줄 154

def write_concern
  @write_concern ||= 만약 wco = @options[:write_concern] || @options[:write]
    writeConcern.get(wco)
  other
    fs.write_concern
  end
end