提交 bcc46316 编写于 作者: B Benjamin Pasero

files - add a method to read content from a position

上级 07ac5720
......@@ -506,6 +506,12 @@ export interface IResolveContentOptions {
* The optional guessEncoding parameter allows to guess encoding from content of the file.
*/
autoGuessEncoding?: boolean;
/**
* Is an integer specifying where to begin reading from in the file. If position is null,
* data will be read from the current file position.
*/
position?: number;
}
export interface IUpdateContentOptions {
......
......@@ -441,10 +441,18 @@ export class FileService implements IFileService {
}
};
let currentPosition: number = (options && options.position) || null;
const readChunk = () => {
fs.read(fd, chunkBuffer, 0, chunkBuffer.length, null, (err, bytesRead) => {
fs.read(fd, chunkBuffer, 0, chunkBuffer.length, currentPosition, (err, bytesRead) => {
totalBytesRead += bytesRead;
if (typeof currentPosition === 'number') {
// if we received a position argument as option we need to ensure that
// we advance the position by the number of bytesread
currentPosition += bytesRead;
}
if (totalBytesRead > MAX_FILE_SIZE) {
// stop when reading too much
finish(new FileOperationError(
......
......@@ -524,7 +524,7 @@ suite('FileService', () => {
test('resolveFile', function (done: () => void) {
service.resolveFile(uri.file(testDir), { resolveTo: [uri.file(path.join(testDir, 'deep'))] }).done(r => {
assert.equal(r.children.length, 7);
assert.equal(r.children.length, 8);
const deep = utils.getByName(r, 'deep');
assert.equal(deep.children.length, 4);
......@@ -540,7 +540,7 @@ suite('FileService', () => {
]).then(res => {
const r1 = res[0].stat;
assert.equal(r1.children.length, 7);
assert.equal(r1.children.length, 8);
const deep = utils.getByName(r1, 'deep');
assert.equal(deep.children.length, 4);
......@@ -879,4 +879,22 @@ suite('FileService', () => {
});
});
});
test('resolveContent - from position (ASCII)', function (done: () => void) {
const resource = uri.file(path.join(testDir, 'small.txt'));
service.resolveContent(resource, { position: 6 }).done(content => {
assert.equal(content.value, 'File');
done();
}, error => onError(error, done));
});
test('resolveContent - from position (with umlaut)', function (done: () => void) {
const resource = uri.file(path.join(testDir, 'small_umlaut.txt'));
service.resolveContent(resource, { position: new Buffer('Small File with Ü').length }).done(content => {
assert.equal(content.value, 'mlaut');
done();
}, error => onError(error, done));
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册