- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我已经研究了一段时间如何将文件内容(在本例中为 excel 文件)流式传输到控制台输出。为 Windows 编译时,使用 THandleStream
结合 STDOUT(控制台输出)句柄就像在公园里散步一样。它使用 Win32 API,因此在为 Linux(顺便说一下 Debian)编译时显然不会工作。
我正在寻找与此等效的内容:
...
aFileStream := TFileStream.Create(FullFileName,fmOpenRead); // This creates the input stream
aOutputStream := THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE)); // Here goes the output stream
aOutputStream.CopyFrom(aFileStream, aFileStream.Size); // And the copy operation
...
更新:以下似乎适用于 Windows,但是一旦我切换到 Linux,它就无法编译,因为 PAnsiChar
未知。
...
f : File;
Buff : PAnsiChar;
BytesRead : integer;
ByteSize : integer;
iBuffRunner : integer;
...
AssignFile(F, 'details.xlsx');
Reset(F,1);
ByteSize := (fileSize(F));
GetMem(Buff,ByteSize);
BlockRead(F,Buff[0],ByteSize,BytesRead);
CloseFile(F);
for iBuffRunner := 0 to (Bytesize-1) do
System.Write(Buff[iBuffRunner]);
FreeMem(Buff);
你能想出一些可能有用的东西吗?
更新:
嗨,雷米,
再次感谢您的帮助!我快到了,还在为最后一点挣扎。您提到我应该能够对 system.output 执行 BlockWrite。但是,BlockWrite 期望 var F: File 作为第一个参数,而 System.Output 是 TEXT 类型?
此外,对于我正在阅读的文件,我正在使用“字节文件”而不是"file",我不确定如何正确转换以输出到控制台?
这是这个 linux POC 的当前状态:
这部分工作正常:阅读 details.xlsx 并将内容写入 test.xlsx(基本上是一个副本)。目标文件与源文件相同。
这部分还没有工作,但最终是我需要的:将 details.xlsx 的内容写入标准输出:
const
MaxBufSize = 4096;
var
f : File of Byte;
tf : File of Byte;
Buff : array of Byte;
BytesRead : integer;
ByteSize : integer;
WillRead : integer;
begin
AssignFile(F, 'details.xlsx');
Reset(F);
ByteSize := (fileSize(F));
if ByteSize > MaxBufSize then
BytesRead := MaxBufSize
else
BytesRead := ByteSize;
SetLength(Buff, BytesRead);
AssignFile(tf, 'test.xlsx');
Rewrite(tf);
try
while ByteSize <> 0 do
begin
if ByteSize > BytesRead then
WillRead := BytesRead
else
WillRead := ByteSize;
BlockRead(F,Buff[0], WillRead);
BlockWrite(tf,Buff[0], WillRead);
//BlockWrite(System.Output, buff[0], WillRead);
Dec(ByteSize, WillRead);
end;
finally
SetLength(Buff,0);
CloseFile(f);
CloseFile(tf);
end;
System.Readln;
end;
最终更新:
const
MaxBufSize = 4096;
var
f : File of Byte;
tf : File of Byte;
Buff : array of Byte;
BytesRead : integer;
ByteSize : integer;
WillRead : integer;
iBufRunner : integer;
begin
AssignFile(F, 'details.xlsx');
Reset(F);
ByteSize := (fileSize(F));
if ByteSize > MaxBufSize then
BytesRead := MaxBufSize
else
BytesRead := ByteSize;
SetLength(Buff, BytesRead);
AssignFile(tf, 'test.xlsx');
Rewrite(tf);
try
while ByteSize <> 0 do
begin
if ByteSize > BytesRead then
WillRead := BytesRead
else
WillRead := ByteSize;
BlockRead(F,Buff[0], WillRead);
BlockWrite(tf,Buff[0], WillRead);
for iBufRunner := 0 to (WillRead - 1) do
System.Write(System.Output, UTF8Char(Buff[iBufRunner]));
Dec(ByteSize, WillRead);
end;
finally
SetLength(Buff,0);
CloseFile(f);
CloseFile(tf);
end;
System.Readln;
end;
最佳答案
我们找到了解决方案:使用 UTF8Char 而不是 AnsiChar 达到了目的。 (参见最终更新)
关于linux - 适用于 Linux 的 Delphi Tokyo : stream file contents to stdout (console output),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46293975/
我正在评估 Tokyo Cabinet Table引擎。在达到100万条记录后,插入速度会大大降低。批量大小为100,000,在事务内完成。我尝试设置xmsiz,但仍然没有用。 Tokyo Cabin
FAL Labs拥有多个东京产品和京都产品: Tokyo Cabinet 和 Kyoto Cabinet 都是轻量级数据库。 Tokyo Tyrant 和 Kyoto Tycoon 都是轻量级数据库服
有人可以引用关于 Tokyo Cabinet 和东京暴君的好教程吗 最佳答案 除了Tokyo Cabinet的官方主页和 Tokyo Tyrant , 我找到了 Ilya Grigorik's blo
只需连续 3 个小时尝试解决 Linux 中 Eclipse 中的 java.lang.UnsatisfiedLinkError: no jtokyocabinet in java.library.p
发现 Delphi Tokyo 中的异常处理行为与以前的 Delphi 版本略有不同。 function FuncTest: integer; begin Result := 1; try
我是 tokyo Cabinet 的新手,我已经安装了它并且我已经运行了示例 C 程序,但出现错误...当我用 gcc 编译时 gcc -O tcadbex.c /tmp/cc7IEOht.o: In
在短暂查看 system.math 的源代码时,我发现64 位版本 Delphi Tokyo 10.2.3 将非正规 IEEE-Doubles 刷新为零,从以下程序中可以看出; {$apptype c
我已经在 TC 上实现了一个队列(具体来说是东京暴君)。我正在使用 memcache 兼容函数增量来跟踪队列头和尾。我只想知道 TC 存储的整数(64 位?)的限制是多少,以及在存储的数字达到允许的最
我正在尝试通过 tokyo-python 包在 Python 中使用 Tokyo Cabinet。我已经安装了 Cabinet 和 Cabinet 开发库。然而,每当我尝试使用 pip 或 easy_
我有多个项目组要批量编译。那里有100多个项目。 2010 年我们有一个这样的“make”文件: call "c:\Borland\RAD Studio\19.0\bin\rsvars.bat" "c
我在一篇名为“动手 Cassandra”的文章中读到 Tokyo Cabinet不利于大数据。为什么? TC 在开始工作之前需要存储多少字节?是否可以确定一个近似值? 最佳答案 基于 this art
我有超过 1 亿个键值对(一个键可以有多个值)。我正在使用 Tokyo Cabinet 的 BDB (B+Tree DB),其键值是 32 位字节数组。 是否可以在 Tokyo Cabinet 中设置
是否可以将 Tokyo Cabinet 与任何 .Net 语言一起使用,最好是 VB10?东京暴君呢?最好不通过 LUA/Ruby 或其他包装器.. 如果没有简单的方法,您能推荐其他可以使用的快速键值
有没有人在大型数据集上成功使用 Tokyo Cabinet/Tokyo Tyrant?我正在尝试上传维基百科数据源的子图。在达到大约 3000 万条记录后,我的速度呈指数级下降。 HDB 和 BDB
它基本上是一个二叉树,它首先搜索哈希来决定它是左还是右: if(hash > rec.hash){ off = rec.left; entoff = rec.off + (sizeof(uin
我在 python 中使用 Tokyo Cabinet 和 tc 模块。我以 TDB 格式存储我的数据。我希望该表仅在写入期间阻塞。不幸的是,我看到当文件以“编写器模式”打开时,其他进程无法从中读取。
我想在运行查询之前确定对 Tokyo Cabinet 表的查询将返回的记录数。我使用 rufus-tokyo Ruby gem 作为我的界面。执行此操作的最佳方法是什么? 最佳答案 仔细查看githu
有人比较过 SimpleDB 和 Tokyo Cabinet 的性能和可伸缩性吗?我目前正在针对 SimpleDB 编写我的项目并考虑对 TC 进行基准测试,如果有人已经完成并可以告诉我是否值得测试我
我正在将用 Delphi 7 编写的旧项目转换为最新版本(Delphi Tokyo),在旧代码中,有一个对文本进行加扰和反扰乱的函数,但是当我使用在 Delphi 中编译的相同程序读取加扰文本时东京只
我对Delphi Tokyo感到非常沮丧。我离开了Delphi Xe7,另一个令人沮丧的错误(内存不足)消失了(或者直到现在为止),但是出现了一个新错误。 当我通过代码仓库更新项目时,通常需要重新构建
我是一名优秀的程序员,十分优秀!