Skip to content

Instantly share code, notes, and snippets.

@kageroh kageroh/ado.wsc
Created Dec 10, 2010

Embed
What would you like to do?
<?xml version="1.0" encoding="utf-8"?>
<component>
<registration
progid="Component.Ado"
classid="{FF2C62D7-CBD3-4F87-A509-38942A006553}"/>
<public>
<method name="loadText">
<parameter name="filename"/>
<parameter name="charset"/>
</method>
<method name="loadLinesOfText">
<parameter name="filename"/>
<parameter name="charset"/>
</method>
<method name="saveText">
<parameter name="filename"/>
<parameter name="text"/>
<parameter name="charset"/>
</method>
<method name="saveFile">
<parameter name="filename"/>
<parameter name="text"/>
</method>
</public>
<object id="stream" progid="ADODB.Stream" />
<reference object="ADODB.Stream" />
<script language="JScript"><![CDATA[
function loadText(filename, charset) {
stream.type = adTypeText;
stream.charset = charset;
stream.open();
stream.loadFromFile(filename);
var text = stream.readText();
stream.close();
return text;
}
function loadLinesOfText(filename, charset) {
var lines = [];
stream.type = adTypeText;
stream.charset = charset;
stream.open();
stream.loadFromFile(filename);
while (!stream.EOS) {
lines.push(stream.readText(adReadLine));
}
stream.close();
return lines;
}
function saveText(filename, text, charset) {
stream.type = adTypeText;
stream.charset = charset;
stream.open();
stream.writeText(text);
stream.saveToFile(filename, adSaveCreateOverWrite);
stream.close();
}
function saveFile(filename, text) {
stream.type = adTypeText;
stream.charset = 'utf-8';
stream.open();
stream.writeText(text);
stream.position = 0;
stream.type = adTypeBinary;
stream.position = 3;
var bin = stream.read();
stream.close();
stream.type = adTypeBinary;
stream.open();
stream.write(bin);
stream.saveToFile(filename, adSaveCreateOverWrite);
stream.close();
}
]]></script>
</component>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.