File: gridfs-chunks-1.phpt

package info (click to toggle)
php-mongo 1.5.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,040 kB
  • ctags: 2,802
  • sloc: ansic: 17,632; xml: 2,195; php: 1,630; pascal: 330; makefile: 52; sh: 39
file content (80 lines) | stat: -rw-r--r-- 1,720 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
--TEST--
GridFS: Testing issues with chunks and reading too much
--SKIPIF--
<?php require_once "tests/utils/standalone.inc"; ?>
--FILE--
<?php
require_once "tests/utils/server.inc";
$conn = mongo_standalone();
$db   = $conn->selectDb(dbname());
$grid = $db->getGridFs('wrapper');

// delete any previous results
$grid->drop();

// dummy file
$bytes = str_repeat("x", 128);
$grid->storeBytes($bytes, array("filename" => "demo.txt", 'chunkSize' => 128), array('w' => true));
unset($bytes);

// fetch it
$file = $grid->findOne(array('filename' => 'demo.txt'));
$chunkSize = $file->file['chunkSize'];

$readSizes = array( 8, 16, 31, 32, 33, 127, 128, 129 );

foreach ($readSizes as $size) {
	$fp = $file->getResource();
	while (!feof($fp)) {
		$t = fread($fp, $size);
		if ($size != strlen($t)) {
			echo "read size(", strlen($t), ") is not the same as requested size ($size)\n";
		} else {
			echo "read: ", strlen($t), " bytes\n";
		}
	}
	fclose($fp);
}
?>
--EXPECT--
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 8 bytes
read: 16 bytes
read: 16 bytes
read: 16 bytes
read: 16 bytes
read: 16 bytes
read: 16 bytes
read: 16 bytes
read: 16 bytes
read: 31 bytes
read: 31 bytes
read: 31 bytes
read: 31 bytes
read size(4) is not the same as requested size (31)
read: 32 bytes
read: 32 bytes
read: 32 bytes
read: 32 bytes
read: 33 bytes
read: 33 bytes
read: 33 bytes
read size(29) is not the same as requested size (33)
read: 127 bytes
read size(1) is not the same as requested size (127)
read: 128 bytes
read size(128) is not the same as requested size (129)