类:Mongo::Grid::File::Chunk

继承:
对象
  • 对象
显示全部
定义于:
lib/ Mongo/grid/ 文件/ 数据块.rb

Overview

封装有关文件数据的GridFS数据段的行为。

由于:

  • 2.0.0

常量摘要折叠

集合 =

数据段集合的名称。

由于:

  • 2.0.0

' chunks '.冻结
DEFAULT_SIZE =

数据块的默认大小。

由于:

  • 2.0.0

(255 * 1024).冻结

实例属性摘要折叠

类方法摘要折叠

实例方法摘要折叠

构造函数详情

#initialize (文档) ⇒ 数据

创建新数据块。

例子:

创建数据段。

Chunk.new(document)

参数:

  • 文档 ( BSON::Document )

    数据块中创建数据段的文档。

由于:

  • 2.0.0



125
126
127
# File 'lib/ Mongo/grid/ 文件/ 数据块.rb', line 125

def 初始化(文档)
  @document = BSON::文档.new(:_id => BSON::ObjectId.new).合并(merge)(文档)
end

实例属性详细信息

# documentBSON::Document (只读)

返回 document 要为数据段存储的文档。

返回:

  • ( BSON::Document )

    document 要为数据段存储的文档。

由于:

  • 2.0.0



39
40
41
# File 'lib/ Mongo/grid/ 文件/ 数据块.rb', line 39

def 文档
  @document
end

类方法详细信息

汇编(数据段) ⇒ string

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

获取数据段数组并将它们重新组合成完整的原始数据。

例子:

组装数据段。

Chunk.assemble(chunks)

参数:

  • 数据块 ( Array<数据段> )

    数据段。

返回:

  • ( string )

    组装的数据。

由于:

  • 2.0.0



159
160
161
# File 'lib/ Mongo/grid/ 文件/ 数据块.rb', line 159

def 汇编(数据块)
  数据块.化简(reduce)(+' '){ |数据, 数据段| 数据 << 数据段.数据.数据 }
end

分割 (io, file_info, offset = 0 ) " > Array

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

将提供的数据拆分为多个数据段。

例子:

将数据拆分为数据段。

Chunks.split(data)

参数:

  • io ( string , IO )

    原始字节。

  • file_info ( File::Info )

    文件集合文件 doc。

  • 偏移量 整数 (默认为: 0

    偏移量。

返回:

由于:

  • 2.0.0



176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/ Mongo/grid/ 文件/ 数据块.rb', line 176

def 拆分(io, file_info, 偏移量 = 0)
  io = StringIO.new(io) if io.is_a?(字符串)
  零件 = 枚举器.new { |y| y << io.(file_info.chunk_size) 直到 io.eof? }
  零件.map.with_index do |字节, n|
    file_info.update_md5(字节)
    数据块.new(
      数据: BSON::二进制文件.new(字节),
      files_id: file_info.id,
      n: n + 偏移量
    )
  end
end

实例方法详细信息

# == (other) ⇒ true , false

检查数据段相等性。

例子:

检查数据段相等性。

chunk == other

参数:

  • 其他 ( Object )

    比较的对象。

返回:

  • ( true , false )

    如果对象相等。

由于:

  • 2.0.0



51
52
53
54
# File 'lib/ Mongo/grid/ 文件/ 数据块.rb', line 51

def ==(其他)
  return false 除非 其他.is_a?(数据块)
  文档 == 其他.文档
end

#bson_typeInteger

获取数据数据块文档的BSON类型。

例子:

获取 BSON 类型。

chunk.bson_type

返回:

  • ( Integer )

    BSON类型。

由于:

  • 2.0.0



64
65
66
# File 'lib/ Mongo/grid/ 文件/ 数据块.rb', line 64

def bson_type
  BSON::哈希::BSON_TYPE
end

#dataBSON::Binary

数据块数据段。

例子:

数据块数据段。

chunk.data

返回:

  • ( BSON::Binary )

    数据段数据。

由于:

  • 2.0.0



76
77
78
# File 'lib/ Mongo/grid/ 文件/ 数据块.rb', line 76

def 数据
  文档[:data]
end

# files_id =" BSON::ObjectId "

获取文件 ID。

例子:

获取文件 ID。

chunk.files_id

返回:

  • ( BSON::ObjectId )

    文件 ID。

由于:

  • 2.0.0



100
101
102
# File 'lib/ Mongo/grid/ 文件/ 数据块.rb', line 100

def files_id
  文档[:files_id]
end

# IDBSON::ObjectId

获取数据块ID。

例子:

获取数据块ID。

chunk.id

返回:

  • ( BSON::ObjectId )

    数据段 ID。

由于:

  • 2.0.0



88
89
90
# File 'lib/ Mongo/grid/ 文件/ 数据块.rb', line 88

def id
  文档[:_id]
end

# n整数

获取数据段位置。

例子:

获取数据段位置。

chunk.n

返回:

  • ( Integer )

    数据块位置。

由于:

  • 2.0.0



112
113
114
# File 'lib/ Mongo/grid/ 文件/ 数据块.rb', line 112

def n
  文档[:n]
end

# to_bson (buffer = BSON::ByteBuffer.new, validating_keys = nil) ⇒ string

将数据段转换为 BSON 以进行存储。

例子:

将BSON 。

chunk.to_bson

参数:

  • 缓冲 ( BSON::ByteBuffer ) (默认为: BSON::ByteBuffer.new

    要附加到的已编码BSON缓冲区。

  • validating_keys ( true , false ) (默认为: nil

    序列化时是否应验证密钥。 此选项已弃用,不会使用。 它将在3.0版本中删除。

返回:

  • ( string )

    原始 BSON 数据。

由于:

  • 2.0.0



141
142
143
# File 'lib/ Mongo/grid/ 文件/ 数据块.rb', line 141

def to_bson(缓冲 = BSON::ByteBuffer.new, validating_keys = nil)
  文档.to_bson(缓冲)
end