TextLogger.limit Member

Limit the data already in the file to the data provided, or the count given.

Syntax

object.limit(dataOrCount);

Arguments

ArgumentSummary
dataOrCount

Returns

Remarks

See Also

Source Code

function tl_limit(dataOrCount)
{
// Find data and count:
var data = null, count = -1;
if (isinstance(dataOrCount, Array))
{
data = dataOrCount;
count = data.length;
}
else if (typeof dataOrCount == "number")
{
count = dataOrCount;
data = this.read();
}
else if (this.autoLimit != -1)
{
count = this.autoLimit;
data = this.read();
}
else
{
throw "Can't limit the length of the file without a limit..."
}
// Write the right data out. Note that we use the back of the array, not
// the front (start from data.length - count), without dropping below 0:
var start = Math.max(data.length - count, 0);
var file = fopen(this.path, ">");
for (var i = start; i < data.length; i++)
file.write(ecmaEscape(data[i]) + "\n");
file.close();
this.appended = 0;
return true;
}