Created
July 3, 2014 05:43
-
-
Save jtyjty99999/ca30abb5a85fa0fe0c17 to your computer and use it in GitHub Desktop.
upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var urlparse = require('url').parse | |
| , http = require('http') | |
| , fs = require('fs'); | |
| function upload(url, uploadfile, callback) { | |
| var urlinfo = urlparse(url); | |
| var options = { | |
| method: 'POST', | |
| host: urlinfo.host, | |
| path: urlinfo.pathname | |
| }; | |
| if(urlinfo.port) { | |
| options.port = urlinfo.port; | |
| } | |
| if(urlinfo.search) { | |
| options.path += urlinfo.search; | |
| } | |
| var req = http.request(options, function(res) { | |
| var chunks = [], length = 0; | |
| res.on('data', function(chunk) { | |
| length += chunk.length; | |
| chunks.push(chunk); | |
| }); | |
| res.on('end', function() { | |
| var buffer = new Buffer(length); | |
| // delay copy | |
| for(var i = 0, pos = 0, size = chunks.length; i < size; i++) { | |
| chunks[i].copy(buffer, pos); | |
| pos += chunks[i].length; | |
| } | |
| res.body = buffer; | |
| callback(null, res); | |
| }); | |
| }); | |
| var readstream = fs.createReadStream(uploadfile); | |
| readstream.on('data', function(chunk) { | |
| console.log('write', chunk.length); | |
| req.write(chunk); | |
| }); | |
| readstream.on('end', function() { | |
| req.end(); | |
| }); | |
| }; | |
| upload('http://weibo.com/', '/tmp/bigfile.pdf', function(err, res) { | |
| console.log(res.statusCode, res.headers); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//
// SA:MP Simple Backup System with ArrayList
//
// Writed by LOUP MC BEAM FOR FOREX GAMMING
//
// 2017
//
#include <a_samp>
#include // Include ArrayList for PAWN
#include // Sscanf for cmd
#include // ZCMD commands
// Defines
#undef MAX_PLAYERS
#define MAX_PLAYERS (50)
#define MAX_ITEMS (10) // Max items per player in inventory
#define INVENTORY_DIALOG (8080)
// Enumerator
enum E_INVENTORY
{
bool: i_used,
i_item_type,
i_item_amount
}
new
PlayerInventory[MAX_PLAYERS][E_INVENTORY][MAX_ITEMS];
// Items
new ItemArray [] [] =
{
{1, "Desert Eagle"},
{2, "Medkit"},
{3, "Burger"}
};
// Declare lists
new
ArrayList:InventoryList[MAX_PLAYERS];
// Callbacks
public OnPlayerConnect(playerid)
{
// Create list
InventoryList[playerid] = NewArrayList(MAX_ITEMS);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
// Clear array
ClearInventory(playerid);
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if (dialogid == INVENTORY_DIALOG)
{
if (response)
{
RemoveItemFromInventory(playerid, listitem + 1);
}
}
return 1;
}
// Functions
stock ClearInventory(playerid)
{
for (new i = 0; i < MAX_ITEMS; i++)
{
PlayerInventory[playerid][i_used][i] = false;
}
ArrayList::Clear(InventoryList[playerid]);
return 1;
}
stock AddItemInInventory(playerid, item_type, item_amount)
{
if (ArrayList::Size(InventoryList[playerid]) < MAX_ITEMS)
{
new
empty_id = ArrayList::Size(InventoryList[playerid]);
}
stock RemoveItemFromInventory(playerid, slot)
{
slot = slot - 1;
}
stock ShowInventory(playerid)
{
new
buffer[1024],
item_name[24],
amount,
get_id = -1;
}
// Commands
CMD:buybackpack(playerid, params[])
{
if (GetPlayerMoney(playerid) < 500)
return SendClientMessage(playerid, -1, "You do not have $500 To get backup");
ShowInventory(playerid);
GivePlayerMoney(playerid, -500);
SendClientMessage(playerid, -1, "You have payed $500 to buy backpack");
return 1;
}
CMD:additem(playerid, params[])
{
new
item,
amount;
}
CMD:remove(playerid, params[])
{
new
slot;
}