How to partially read from a TStringStream, free the read data from the stream and keep the rest (the unread data)?
Tag : string , By : user182548
Date : March 29 2020, 07:55 AM
like below fixes the issue You cannot do what you are hoping to do. The string stream's data is a Delphi string which is stored as a single memory block. Memory blocks are atomic, they cannot be split. You cannot free some part of a memory block. If you really need to return memory to the memory manager then you should create a new string with the already processed data removed. You can then re-create your string stream with this new input and destroy the previous string stream.
|
No data is read in SqlReader Invalid attempt to read when no data is present.
Date : March 29 2020, 07:55 AM
it helps some times I know this problem has been posted millions of times before, but this might be different. , If you can change the signature of your Handler, then: public bool <YourHandlerName>(out MemoryStream ms)
{
SqlConnection conn = new SqlConnection(@"Server=DEV6\MSSQLHOSTING;Database=Intranet;Trusted_Connection=True;");
conn.Open();
SqlCommand cmd = new SqlCommand("select PDFDocument from LeaveChart where (Year like @Year and Month like @Month)", conn);
cmd.Parameters.AddWithValue("Year", context.Request.QueryString["Year"]);
cmd.Parameters.AddWithValue("Month", context.Request.QueryString["Month"]);
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
ms = new MemoryStream(content);
if(reader.HasRows)
{
byte[] content = (byte[])reader.GetValue(0);
ms.Position = 0;
context.Response.ContentType = "Application/pdf";
ms.WriteTo(context.Response.OutputStream);
context.Response.End();
reader.Close();
conn.Close();
return true;
}
return false;
}
|
How to use Node.js to read data from a json file and display the read data into html?
Date : March 29 2020, 07:55 AM
Hope that helps The http module doesn't support Objects as a response (it supports buffers or a strings) so you have to do this: res.end(JSON.stringify(data));
res.send(data);
|
Cannot Read property 'data' of undefined (Angularjs- not able to read data from template to controller)
Date : March 29 2020, 07:55 AM
Any of those help The reason is the controller has to run before it can render the view, not the other way around. So at the time you try to log the data it doesn't exist
|
How to add additional data with data read from a node stream in read callback handler?
Date : March 29 2020, 07:55 AM
this one helps. A possible solution follows (am marking this as the answer unless I get a better answer): var fs = require('fs');
var path = require('path');
var JSONStream = require('JSONStream');
var through = require('through2');
var tmp1 = path.join(__dirname, 'data', 'tmp1.json');
var tmp2 = path.join(__dirname, 'data', 'tmp2.json');
[tmp1, tmp2]
.map(p => fs.createReadStream(p))
.map(stream => [path.parse(stream.path), stream.pipe(JSONStream.parse())])
.map(([parsedPath, jsonStream]) => {
return jsonStream.pipe(through.obj(function (obj, _, cb) {
this.push({
fileName: parsedPath.name,
data: obj
});
cb();
}));
})
.map(stream => {
stream.on('data', function (data) {
console.log(JSON.stringify(data, null, 2));
});
})
;
{
"fileName": "tmp1",
"data": {
"a": 1,
"b": 2
}
}
{
"fileName": "tmp1",
"data": {
"a": 3,
"b": 4
}
}
{
"fileName": "tmp1",
"data": {
"a": 5,
"b": 6
}
}
{
"fileName": "tmp2",
"data": {
"a": 100,
"b": 200
}
}
{
"fileName": "tmp2",
"data": {
"a": 300,
"b": 400
}
}
{
"fileName": "tmp2",
"data": {
"a": 500,
"b": 600
}
}
|