-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathnodejs-documents-binary-mp3.js
More file actions
80 lines (70 loc) · 2.47 KB
/
Copy pathnodejs-documents-binary-mp3.js
File metadata and controls
80 lines (70 loc) · 2.47 KB
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
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var should = require('should');
var fs = require('fs');
var stream = require('stream');
var util = require('util');
var concatStream = require('concat-stream');
var valcheck = require('core-util-is');
var testconfig = require('../etc/test-config-qa.js');
var marklogic = require('../');
var q = marklogic.queryBuilder;
var dbReader = marklogic.createDatabaseClient(testconfig.restReaderConnection);
var dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnection);
var dbAdmin = marklogic.createDatabaseClient(testconfig.restAdminConnection);
describe('Binary documents test', function () {
var binaryPath = __dirname + '/data/mediaCQ.mp3';
var uri = '/test/binary/someMp3File.mp3';
var binaryValue = null;
before(function (done) {
this.timeout(10000);
fs.createReadStream(binaryPath).
pipe(concatStream({ encoding: 'buffer' }, function (value) {
binaryValue = value;
done();
}));
});
it('should write the binary with Readable stream', function (done) {
this.timeout(10000);
var uri = '/test/write/someMp3File.mp3';
var readableBinary = new ValueStream(binaryValue);
//readableBinary.pause();
dbWriter.documents.write({
uri: uri,
contentType: 'audio/mpeg',
content: readableBinary
}).
result(function (response) {
response.should.have.property('documents');
done();
}, done);
});
it('should read the binary with Readable stream', function (done) {
this.timeout(10000);
var uri = '/test/write/someMp3File.mp3';
dbReader.documents.read(uri).
result(function (documents) {
JSON.stringify(binaryValue).should.equal(
JSON.stringify(documents[0].content));
done();
}, done);
});
it('should delete mp3 file', function (done) {
dbAdmin.documents.removeAll({
all: true
}).
result(function (response) {
done();
}, done);
});
});
function ValueStream(value) {
stream.Readable.call(this);
this.value = value;
}
util.inherits(ValueStream, stream.Readable);
ValueStream.prototype._read = function () {
this.push(this.value);
this.push(null);
};